24小时热门版块排行榜    

查看: 390  |  回复: 0
当前主题已经存档。

sdlj8051

金虫 (著名写手)

[交流] 通过IP地址查找主机名 findip.c

/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* Filename: findip.c
* Created : Nov. 10th 1995 @ 4:30pm
* Author  : SrfRoG (srfrog@itek.net)
* Descrip.: This cute little program will attempt to resolve
*   an IP address to its hostname. Then prints the results
*   to standard output.
* ---------------------------------------------------------------------
* To compile this program:
* Linux: gcc -O2 -m486 -s -o findip findip.c
* AIX, BSD: gcc -O2 -s -o findip findip.c
* SunOS: gcc -O2 -lnsl -s -o findip findip.c
* Other: cc -o findip findip.c
*/

#i nclude
#i nclude
#i nclude
#i nclude
#i nclude
#i nclude

int main(argc, argv)
int argc;
char **argv;
{   
struct hostent *ip;
unsigned long hostname;

if (argc != 2)
{
printf("Need to specify an IP address.\n";
exit(1);
}  
if ((hostname = inet_addr(argv[1])) == -1)
{
printf("Could not find %s\n", argv[1]);
exit(1);
}
if ((ip = gethostbyaddr((char *)&hostname, sizeof(long), AF_INET)) != NULL)
printf("%s is %s\n", argv[1], ip->h_name);
else
printf("Could not resolve %s\n", argv[1]);
return 0;
}

[ Last edited by 幻影无痕 on 2006-11-9 at 07:56 ]
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 sdlj8051 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 085404电子信息284分求调剂 +4 13659058978 2026-03-24 4/200 2026-03-24 12:15 by syl20081243
[考研] 求调剂 +5 研研,接电话 2026-03-24 6/300 2026-03-24 11:39 by 星空星月
[考研] 一志愿哈工大,085400,320,求调剂 +3 gdlf9999 2026-03-24 3/150 2026-03-24 10:08 by 搏击518
[考研] 一志愿211 初试270分 求调剂 +4 谷雨上岸 2026-03-23 5/250 2026-03-23 21:18 by 不惑可乐
[考研] 333求调剂 +3 ALULU4408 2026-03-23 3/150 2026-03-23 19:04 by macy2011
[考研] 一志愿中国石油大学(华东) 本科齐鲁工业大学 +4 石能伟 2026-03-17 4/200 2026-03-23 17:51 by 17862566385
[考研] 招08考数学 +6 laoshidan 2026-03-20 14/700 2026-03-23 14:37 by 15614359529
[考研] 319求调剂 +4 小力气珂珂 2026-03-20 4/200 2026-03-22 15:53 by ColorlessPI
[考研] 298求调剂一志愿211 +3 上岸6666@ 2026-03-20 3/150 2026-03-22 15:50 by ColorlessPI
[考研] 材料工程专硕 348分求调剂 +3 冬辞. 2026-03-17 5/250 2026-03-21 18:47 by 学员8dgXkO
[考研] 求调剂 +6 Mqqqqqq 2026-03-19 6/300 2026-03-21 08:04 by JourneyLucky
[考研] 化学求调剂 +4 临泽境llllll 2026-03-17 5/250 2026-03-21 02:23 by JourneyLucky
[考研] 324分 085600材料化工求调剂 +4 llllkkkhh 2026-03-18 4/200 2026-03-21 01:24 by JourneyLucky
[考研] 南京大学化学376求调剂 +3 hisfailed 2026-03-19 6/300 2026-03-20 23:43 by hisfailed
[考研] 288求调剂 +16 于海海海海 2026-03-19 16/800 2026-03-20 22:28 by JourneyLucky
[考研] 329求调剂 +9 想上学吖吖 2026-03-19 9/450 2026-03-20 22:01 by luoyongfeng
[考研] 295材料求调剂,一志愿武汉理工085601专硕 +5 Charlieyq 2026-03-19 5/250 2026-03-20 20:35 by JourneyLucky
[考研] 一志愿南理工085701环境302求调剂院校 +3 葵梓卫队 2026-03-20 3/150 2026-03-20 19:28 by zhukairuo
[考研] 材料学硕318求调剂 +5 February_Feb 2026-03-19 5/250 2026-03-19 23:51 by 23Postgrad
[考研] 320求调剂0856 +3 不想起名字112 2026-03-19 3/150 2026-03-19 22:53 by 学员8dgXkO
信息提示
请填处理意见