怎样用VC++编程显示本机的主机名和IP地址
发布网友
发布时间:2022-05-02 11:47
我来回答
共1个回答
热心网友
时间:2022-06-19 23:00
#include<winsock2.h>
#include<stdio.h>
#pragma comment(lib,"WS2_32.lib")
int main()
{
WSADATA data;
WSAStartup(2,&data);
hostent* host = gethostbyname("");
char *IP = inet_ntoa(*(struct in_addr*)*(host->h_addr_list));
printf("Local IP:%s\n",IP);
WSACleanup();
return 0;
}