24小时热门版块排行榜    

查看: 386  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 0856化工专硕求调剂 +11 董boxing 2026-03-01 11/550 2026-03-01 19:04 by 18137688336
[考研] 一志愿中南大学理学化学 +4 15779376950 2026-03-01 5/250 2026-03-01 19:00 by Fff-1
[考研] 295求调剂 +7 19171856320 2026-02-28 7/350 2026-03-01 18:54 by 18137688336
[考研] 材料类求调剂 +10 wana_kiko 2026-02-28 11/550 2026-03-01 18:11 by 海嵙Y
[考研] 高分子化学与物理调剂 +6 好好好1233 2026-02-28 11/550 2026-03-01 17:47 by 好好好1233
[考研] 290求调剂 +9 材料专硕调剂; 2026-02-28 11/550 2026-03-01 17:21 by sunny81
[考研] 材料学硕318求调剂 +8 February_Feb 2026-03-01 10/500 2026-03-01 16:48 by sunny81
[考研] 材料工程274求调剂 +3 Lilithan 2026-03-01 3/150 2026-03-01 14:58 by ms629
[考研] 求调剂 +6 repeatt?t 2026-02-28 6/300 2026-03-01 14:37 by Sakura绘
[考研] 课题组接收材料类调剂研究生 +3 gaoxiaoniuma 2026-02-28 4/200 2026-03-01 14:30 by jjj三跨
[考研] 295复试调剂 +3 简木ChuFront 2026-03-01 3/150 2026-03-01 14:27 by zzxw520th
[考研] 298求调剂 +9 人间唯你是清欢 2026-02-28 12/600 2026-03-01 14:23 by Ducount.Y
[考研] 材料284求调剂,一志愿郑州大学英一数二专硕 +10 想上岸的土拨鼠 2026-02-28 10/500 2026-03-01 14:12 by yc258
[考研] 化工299分求调剂 一志愿985落榜 +4 嘻嘻(*^ω^*) 2026-03-01 4/200 2026-03-01 13:15 by wang_dand
[考研] 调剂 +3 简木ChuFront 2026-02-28 3/150 2026-03-01 11:46 by 王伟要上岸啊
[考研] 寻找调剂 +4 LYidhsjabdj 2026-02-28 4/200 2026-03-01 10:56 by sunny81
[考博] 博士自荐 +4 kkluvs 2026-02-28 4/200 2026-03-01 10:19 by 馥安馥安
[考研] 304求调剂 +3 52hz~~ 2026-02-28 5/250 2026-03-01 00:00 by 52hz~~
[考研] 264求调剂 +3 巴拉巴拉根556 2026-02-28 3/150 2026-02-28 21:31 by gaoxiaoniuma
[考研] 085600材料工程一志愿中科大总分312求调剂 +8 吃宵夜1 2026-02-28 10/500 2026-02-28 20:27 by L135790
信息提示
请填处理意见