您的位置:首页 > 其它

域名转换IP的一种实现方法

2014-09-18 19:27 323 查看
#include <Windows.h>
#include <iostream>
#include <WinSock.h>
#pragma comment(lib, "ws2_32.lib")
#include <string>
using namespace std;

void main()
{
WSADATA wsadata;
WSAStartup(0x0101, &wsadata);

string hostName;
cout<<"请输入要查询的主机名称:";
cin>>hostName;
HOSTENT * host_entry = gethostbyname(hostName.c_str());
if(host_entry != 0)
{
for (int i=0; host_entry->h_addr_list[i]; i++)
{
printf("%s\n", inet_ntoa(*((in_addr *)host_entry->h_addr_list[i])));
}
}
WSACleanup();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: