DNS服务常用工具

来源:互联网 发布:淘宝主营占比 编辑:程序博客网 时间:2024/05/10 19:37

1 nslookup  

备注:在winxp中还有此交互命令

例 1:

C:>c:/windows/system32/nslookup
Default Server:  hangzhou.zjhzptt.net.cn
Address:  202.101.172.35

> sina
Server:  hangzhou.zjhzptt.net.cn
Address:  202.101.172.35

DNS request timed out.
    timeout was 2 seconds.
*** Request to hangzhou.zjhzptt.net.cn timed-out
> sina.com.cn
Server:  hangzhou.zjhzptt.net.cn
Address:  202.101.172.35

Non-authoritative answer:
Name:    sina.com.cn
Address:  202.108.33.32

> exit

2 host

注:linux/unix系可能会有

3 用gethostbyname 和 gethostbyaddr 编程实现

备注:作者的机器上用gethostbyaddr获得广域网的域名尚未成功过,以下代码仅供参考

  PHOSTENT phost;
  in_addr inAddr;
  phost = gethostbyname("sina.com.cn");
  inAddr.s_addr = ((struct in_addr far *)(phost->h_addr))->s_addr;
  printf("%s 's ip is %s/n", phost->h_name, inet_ntoa(inAddr));

  char ip[20] = "192.168.1.121/0";

  u_long res = inet_addr(ip);
  if(res == INADDR_NONE)
   printf("error!/n");
  phost = gethostbyaddr((char*)&res, sizeof(res), AF_INET);
  if(phost){
   printf("%s 's hostname is %s/n", ip, phost->h_name);
  }else
   printf("error!/n");

原创粉丝点击