24小时热门版块排行榜    

Znn3bq.jpeg
汕头大学海洋科学接受调剂
查看: 400  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 327求调剂 +11 Xxjc1107. 2026-04-13 11/550 2026-04-13 15:28 by chw1980_0
[考研] 一志愿211 0703化学 346分求调剂 +26 土豆er? 2026-04-09 29/1450 2026-04-13 15:15 by 独醉梦孤城
[考研] 材料工程085601,270求调剂 +38 @ASDF1234 2026-04-08 41/2050 2026-04-13 12:53 by 张zhihao
[考研] 339求调剂 +4 hanwudada 2026-04-12 4/200 2026-04-13 12:03 by 蓝云思雨
[考研] 电气工程专硕320求调剂 +5 小麻子111 2026-04-10 5/250 2026-04-12 10:47 by zhouyuwinner
[考研] 22专硕求调剂 +6 haoyun上岸 2026-04-11 8/400 2026-04-11 23:21 by labixiaoqiao
[考研] 求调剂 +6 小聂爱学习 2026-04-11 9/450 2026-04-11 21:20 by 蓝云思雨
[考研] 调剂 +6 青灯不负 2026-04-09 6/300 2026-04-11 20:35 by dongdian1
[考研] 调剂求助 +6 果然有我 2026-04-11 7/350 2026-04-11 16:22 by 明月此时有
[考研] 085500求调剂材料 +10 易11122 2026-04-09 10/500 2026-04-11 10:39 by maddjdld
[考研] 087100初试311求调剂 +4 任雅琴 2026-04-09 4/200 2026-04-11 10:33 by zhq0425
[考研] 机械专硕270求调剂,接受跨专业 +12 老师看看我吧aba 2026-04-09 14/700 2026-04-11 10:21 by laoshidan
[考研] 广东省 085601 329分求调剂 +14 Eddieddd 2026-04-10 14/700 2026-04-11 09:58 by bljnqdcc
[考研] 282,求调剂 +12 jggshjkkm 2026-04-09 14/700 2026-04-11 09:39 by 猪会飞
[考研] 一志愿矿大,材料工程专硕314分,0856可调都可以 +15 无懈可击的巨人 2026-04-09 15/750 2026-04-10 18:10 by hmn_wj
[考研] 298求调剂 +13 钉叮咚冬瓜 2026-04-09 13/650 2026-04-10 15:49 by jiajinhpu
[考研] 070300化学 求调剂 +13 73372112 2026-04-08 13/650 2026-04-09 20:22 by maddjdld
[论文投稿] 求助文献原文 10+3 18500821399 2026-04-08 3/150 2026-04-09 16:56 by 北京莱茵润色
[考研] 283电子信息求调剂 +4 三石WL 2026-04-08 4/200 2026-04-09 10:21 by wp06
[考研] 求调剂 +3 猪肉墩粉条cc 2026-04-08 4/200 2026-04-09 10:05 by 猪肉墩粉条cc
信息提示
请填处理意见