MFC获取本机IP

来源:互联网 发布:seo基础入门教程 编辑:程序博客网 时间:2024/05/20 00:13

WSADATA wsaData;

         WORDsockVersion = MAKEWORD(2, 2);

         WSAStartup(sockVersion,&wsaData);

         charhost_name[225];

         gethostname(host_name,sizeof(host_name));

         structhostent *phe = gethostbyname(host_name);

         structin_addr addr;

         memcpy(&addr,phe->h_addr_list[0], sizeof(struct in_addr));

         char*ipAddress = inet_ntoa(addr);

         WSACleanup();

         CStringmyip;

         myip.Format("%s",ipAddress);

         AfxMessageBox(myip);

0 0