void GetIP()
{
char host_name[MAX_PATH] = {0};
int ret = gethostname(host_name, sizeof(host_name));
if(ret != 0)
{
return;
}
hostent *host = NULL;
host = gethostbyname(host_name);
if(NULL == host)
{
return;
}
BYTE *b = reinterpret_cast<BYTE*>(host->h_addr_list[0]);
char ip[16] = {0};
sprintf_s(ip, "%d.%d.%d.%d", b[0], b[1], b[2], b[3]);
int nSize = MultiByteToWideChar(CP_ACP, 0, ip, sizeof(ip), NULL, 0);
wchar_t *wcs_ip = new wchar_t[nSize];
memset(wcs_ip, 0, nSize);
MultiByteToWideChar(CP_ACP, 0, ip, sizeof(ip), wcs_ip, nSize);
delete [] wcs_ip;
}
得到本地IP
最新推荐文章于 2024-08-26 21:31:14 发布