// GetIp.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include#include #pragma comment(lib,"WS2_32.lib")using namespace std;int _tmain(int argc, _TCHAR* argv[]){ WSADATA wsd; if(WSAStartup(MAKEWORD(2,2),&wsd) != 0) { return -1; } char szHostname[100],szHostaddress[200]; if(gethostname(szHostname,sizeof(szHostname)) != SOCKET_ERROR) { HOSTENT *pHostEnt = gethostbyname(szHostname); if(pHostEnt != NULL) { sprintf(szHostaddress,"%d.%d.%d.%d", (pHostEnt->h_addr_list[0][0]&0x00ff), (pHostEnt->h_addr_list[0][1]&0x00ff), (pHostEnt->h_addr_list[0][2]&0x00ff), (pHostEnt->h_addr_list[0][3]&0x00ff)); } } cout << szHostaddress << endl; return 0;}