如何通过域名转ip

has39 2006-04-19 09:35:01
谁给段代码?

比如输入www.sina.com.cn 可以得到 ip为218.30.66.67
...全文
1333 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixiaosan 2006-04-19
  • 打赏
  • 举报
回复
大意了。。。没注意是远程的。。
goodboyws 2006-04-19
  • 打赏
  • 举报
回复
#include <windows.h>
#include <winsock.h>
#include <stdio.h>

void main()
{
WSADATA wsaData;
char szHostname[100];
HOSTENT *pHostEnt;
int nAdapter = 0;
struct sockaddr_in sAddr;

if (WSAStartup(0x0101, &wsaData))
{
printf("WSAStartup failed %s\n", WSAGetLastError());
return;
}

pHostEnt = gethostbyname( "www.sina.com.cn");

while ( pHostEnt->h_addr_list[nAdapter] )
{
// pHostEnt->h_addr_list[nAdapter] is the current address in host
// order.

// Copy the address information from the pHostEnt to a sockaddr_in
// structure.
memcpy ( &sAddr.sin_addr.s_addr, pHostEnt->h_addr_list[nAdapter],
pHostEnt->h_length);

// Output the machines IP Address.
printf("Name: %s\nAddress: %s\n", pHostEnt->h_name,
inet_ntoa(sAddr.sin_addr));

nAdapter++;
}
WSACleanup();
return;

}
lixiaosan 2006-04-19
  • 打赏
  • 举报
回复
gethostbyname
龙凤呈祥焱 2006-04-19
  • 打赏
  • 举报
回复
WINDOWS有提供DNS解析命令啊!!!1

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧