荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: lczhong (lcz), 信区: Program
标 题: 如何得到形如xxx.xxx.xxx.xxx字串形式的本机IP
发信站: BBS 荔园晨风站 (Thu Mar 15 18:33:30 2001), 站内信件
发信人: Smile (呵呵~~我的昵称不见了), 信区: SOCKET
标 题: 如何得到形如xxx.xxx.xxx.xxx字串形式的本机IP
发信站: 武汉白云黄鹤站 (2001年03月14日07:42:25 星期三), 站内信件
char szHostName[128];
if( gethostname(szHostName, 128) == 0 )
{ // Get host adresses
struct hostent * pHost;
int i;
pHost = gethostbyname(szHostName);
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++
) { CString str;
int j;
for( j = 0; j < pHost->h_length; j++ )
{ CString addr;
if( j > 0 )
str += ".";
addr.Format("%u",
(unsigned
int )((unsigned char*)pHost->h_addr_list[i])[j]);
str += addr;
}
// str now contains one local IP address - do whatever you want to
do w ith it (probably add it to a list)
}
}
--
┏━━┓┏━━┓ ☆ ┏━┓ ┏━━┓
┃ ━┫┃ ┃ ┏┓ ┃ ┃ ┃ ━┫
┣━ ┃┃┃┃┃ ┃┃ ┃ ┗┓┃ ━┫
┗━━┛┗┻┻┛ ┗┛ ┗━━┛┗━━┛
※ 来源:·武汉白云黄鹤站 bbs.whnet.edu.cn·[FROM: 211.69.197.130]
--
☆ 来源:.BBS 荔园晨风站 bbs.szu.edu.cn.[FROM: bbs@192.168.28.105]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店