一:
你可以使用一些命令来做那些查找。比如,Linux使用host命令,但Windows使用nslookup。
Host命令
host命令接受带主机域名全称或IP地址的参数。要进行前向查找,使用如下命令行:
[root@bigboy tmp]# host www.ithov.com www.ithov.com has address 65.115.71.34 [root@bigboy tmp]#
要进行反向查找
[root@bigboy tmp]# host 65.115.71.34 34.71.115.65.in-addr.arpa domain name pointer 65-115-71-34.myisp.net. [root@bigboy tmp]#
如你所见,前向查找和反向查找结果不匹配。反向查找结果与ISP匹配。
nslookup命令
nslookup命令给Windows电脑提示类似的功能。要进行前向查找,使用:
C:\> nslookup www.ithov.com Server: 192-168-1-200.my-site.com Address: 192.168.1.200 Non-authoritative answer: Name: www.ithov.com Address: 65.115.71.34 C:\>
要进行反向查找
C:\> nslookup 65.115.71.34 Server: 192-168-1-200.my-site.com Address: 192.168.1.200 Name: 65-115-71-34.my-isp.com Address: 65.115.71.34 C:\>二
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- int main(int argc ,char **argv)
- {
- struct sockaddr_in addr;
- struct hostent *host;
- char **alias;
- if(argc<2)
- {
- fprintf(stderr,"Usage:%s hostname|ip..\n\a",argv[0]);
- exit(1);
- }
- argv++;
- for(;*argv!=NULL;argv++)
- {
- /* 这里我们假设是IP*/
- if(inet_aton(*argv,&addr.sin_addr)!=0)
- {
- host=gethostbyaddr((char *)&addr.sin_addr,4,AF_INET);
- printf("Address information of Ip %s\n",*argv);
- }
- else
- {
- /* 域名*/
- host=gethostbyname(*argv); printf("Address information of host %s\n",*argv);
- }
- if(host==NULL)
- {
- /* 找不到*/
- fprintf(stderr,"No address information of %s\n",*argv);
- continue;
- }
- printf("Official host name %s\n",host->h_name);
- printf("Name aliases:");
- for(alias=host->h_aliases;*alias!=NULL;alias++)
- printf("%s ,",*alias);
- printf("\nIp address:\n");
- for(alias=host->h_addr_list;*alias!=NULL;alias++)
- printf("%s \n ,",inet_ntoa(*(struct in_addr *)(*alias)));
- }
- return 0;
- }