首页 > 其他 > 详细

VC获取计算机名和IP地址

时间:2015-01-21 22:09:54      阅读:405      评论:0      收藏:0      [点我收藏+]
void GetPcNameAndIp(CString &strPCName,vector<CString> &vIp)
{
	vIp.clear();	 
	WSADATA wsadata; 
	WORD dwVersionRequested; 
	int err = WSAStartup(dwVersionRequested,&wsadata); 
	char hostname[128]; 
	if(gethostname(hostname,128)==0) 
	{ 
		strPCName.Format("%s",hostname);
	} 
	char buf[20];
	struct hostent *pHost = gethostbyname(hostname);

	CString strTmp;
	for (int i = 0; pHost != NULL && pHost->h_addr_list[i] != NULL; i++) 
	{   
		strcpy_s(buf,inet_ntoa(*(struct in_addr *)pHost->h_addr_list[i]));
		strTmp.Format("%s",buf);
		vIp.push_back(strTmp);
	} 

	WSACleanup();
}

 

VC获取计算机名和IP地址

原文:http://www.cnblogs.com/liuxupiaoshi/p/4239967.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!