获取主机的IP
#include<iostream>
#include<string>
#pragma comment(lib,"wsock32.lib")
#include<winsock2.h>
using namespace std;
void main()
{
char hostname[128]="qsd-PC";
const char* addr;
struct hostent *phost;
if(gethostname(hostname,128)==0)
{
phost=gethostbyname(hostname);
for(int i=0;phost!=NULL&&phost->h_addr_list[i]!=NULL;i++)
{
addr=inet_ntoa(*(struct in_addr*)phost->h_addr_list[i]);
printf("%s\n",addr);
}
}