6.3w+
社区成员
#include <Windows.h>
#include <WinSock.h>
int WSAReturn;
WSADATA WSAData;
HOSTENT *hostEntry;
char hostName[256];
char hostAddress[256];//host ip
int APIENTRY WinMain( __in HINSTANCE hInstance,
__in_opt HINSTANCE hPrevInstance,
__in_opt LPSTR lpCmdLine,
__in int nShowCmd )
{
WSAReturn = WSAStartup(0x0101,&WSAData);
if (WSAReturn == 0)
{
gethostname(hostName,256);
hostEntry = gethostbyname(hostName);
if (hostEntry != 0)
{
wsprintf(hostAddress,"%d.%d.%d.%d",
(hostEntry->h_addr_list[0][0]&0x00ff),
(hostEntry->h_addr_list[0][1]&0x00ff),
(hostEntry->h_addr_list[0][2]&0x00ff),
(hostEntry->h_addr_list[0][3]&0x00ff));
MessageBox(NULL,hostAddress,hostName,MB_OK);
}
}
WSACleanup();
return 0;
}
#pragma comment( lib , "ws2_32.lib")//加上这个