急!急!急! 在线等待……
如何获得本地计算机的IP或者Name? 问题点数:100、回复次数:4Top
1 楼w_mac(wendy)回复于 2002-07-28 19:27:00 得分 10
你可以到http://www.helpwork.net网战的 代码处看看。Top
2 楼xuying()回复于 2002-07-28 19:37:22 得分 30
用gethostname()得到主机名,
用gethostbyname()得到ip地址。
char msgHostname[10];
LPHOSTENT local;
LPSTR szIPAddr;
CString msg;
gethostname(msgHostname,10);
AfxMessageBox(msgHostname);
local = gethostbyname(msgHostname);
if (!local)
AfxMessageBox("Could not get IP address!");
else
{
szIPAddr = inet_ntoa(*(LPIN_ADDR)*(local->h_addr_list));
msg.Format("Host name is:%s, IP address is:%s",msgHostname,szIPAddr);
AfxMessageBox(msg);
}
Top
3 楼ThisTimeThree()回复于 2002-07-28 19:38:09 得分 10
简单方法是用socket函数gethostname( the character name of local host)和gethostbyname(ip, need host name as input);Top
4 楼kittity(kittity)回复于 2002-07-28 19:43:16 得分 50
用Api : GetComputerName()不用socket就可以得到本机名Top




