/*头文件*/
#include "winsock2.h" #pragma comment(lib,"ws2_32.lib") /*Hui 获取当前服务器IP*/
WSADATA wsaData;
char name[];
char *ip;
PHOSTENT hostinfo;
if ( WSAStartup( MAKEWORD(,), &wsaData ) == )
{
if( gethostname ( name, sizeof(name)) == )
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
printf("当前服务器IP:%s\n", ip);
}
}
WSACleanup( );
}
/*END*/