Rrouned

/************************************************************************/
/* 域名到IP的转换 */
/************************************************************************//

#include <winsock2.h>
#include <stdio.h>

#pragma comment(lib,"ws2_32.lib")

const char str[20]={0};
char *hostIP=0;

void main()
{
//初始化库,没他不行
WSADATA wsa;
if (WSAStartup(MAKEWORD(2,2),&wsa)!=0)
{
printf("Winsock Initialization failed.\n");
return;
}

//gethostbyname获得域名对应的IP
hostent *hp = gethostbyname(str);
if (hp)
{
//inet_ntoa把IP转换成文本型
hostIP = inet_ntoa(*(struct in_addr *)*hp->h_addr_list);
printf("host IP:%s\n",hostIP);

}
}

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
  • 2021-10-26
  • 2021-05-25
  • 2021-10-16
猜你喜欢
  • 2021-12-28
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2018-04-20
相关资源
相似解决方案