zoukankan
html css js c++ java
通过域名显示IP列表
#define
__LINUX__
#include
<
stdio.h
>
#ifdef __LINUX__
#include
<
netdb.h
>
#include
<
sys
/
socket.h
>
#else
#include
<
winsock2.h
>
#pragma
comment(lib, "ws2_32.lib")
#endif
int
main(
int
argc,
char
*
argv[])
{
struct
hostent
*
hptr;
char
**
pptr;
char
hostname[
32
];
char
str[
32
];
#ifndef __LINUX__
WSADATA wsa;
WSAStartup(MAKEWORD(
2
,
2
),
&
wsa);
#endif
if
(gethostname(hostname,
sizeof
(hostname)))
{
#ifdef __LINUX__
printf(
"
gethostname calling error: %d \n
"
);
#else
printf(
"
gethostname calling error: %d \n
"
, WSAGetLastError());
#endif
return
1
;
}
printf(
"
localhost name: %s\n
"
, hostname);
strcpy(hostname, argv[
1
]);
if
((hptr
=
gethostbyname(hostname))
==
NULL)
{
printf(
"
gethostbyname calling error\n
"
);
return
1
;
}
int
i
=
0
;
pptr
=
hptr
->
h_addr_list;
for
(;
*
pptr
!=
NULL; pptr
++
)
{
#ifdef __LINUX__
printf(
"
address: %s \n
"
, inet_ntop(hptr
->
h_addrtype,
*
pptr, str,
sizeof
(str)));
#else
printf(
"
address: %s \n
"
, inet_ntoa(
*
( (
struct
in_addr
*
)hptr
->
h_addr_list[i] )));
i
++
;
#endif
}
return
0
;
}
查看全文
相关阅读:
基于node.js+socket.io+html5实现的斗地主游戏(1)概述
[javascript]switchTab:仿腾讯首页Tab栏切换js插件
[js]利用闭包向post回调函数传参数
[CSS]利用伪元素实现一些特殊图形 from baidu校招
[javascript]模块化&命名污染—from 编程精解
[随手记]2014前端面试题解
[IE bug] ajax请求 304解决方案
[java]基于UDP的Socket通信Demo
[JQuery]ScrollMe滚动特效插件
java.lang.OutOfMemoryError及解决方案
原文地址:https://www.cnblogs.com/frischzenger/p/1584672.html
最新文章
编程之美系列01
计算机网络纲要
你也许还不知道const_cast,static_cast,dynamic_cast,reinterpret_cast的区别吧?
一个基本问题引出的话题,类常识你知多少?
C++指针、引用知多少?
C++中static、const使用方法简介
C++中数据对齐问题。struct、union、enum,类继承。再谈sizeof()
一道面试题想到的
句子单词的逆转
KMP,模式匹配算法
热门文章
unity3d杂录【1】
使用IntelliLock加密授权你的.Net程序 【转载】
C#使用Dotfuscator混淆代码以及加密【转载】
如何使用Photon引擎开发MMO大型多人在线游戏 简易版教程(by 白杨学士)【转载】
Visual studio 使用正则表达查找替换
C++模板小结【转载】
关于C++类中的前向声明
C++类型转换总结【转】
LUA语言参考【转】
C#与Java的比较(转)
Copyright © 2011-2022 走看看