#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(int argc,char *argv[]){
struct sockaddr_in addr;
struct hostent *he;
char **alias;
if(argc<2){
printf("Usage:%s name |IP",argv[0]);
exit(1);
}
argv++;
for(;*argv!=NULL;argv++){
if(inet_aton(*argv,&addr.sin_addr)!=0){
he=gethostbyaddr((char *)&addr,sizeof(addr),AF_INET);
printf("address information of IP %s:\n",*argv);
}else{
he=gethostbyname(*argv);
printf("address information of host %s:\n",*argv);
}
if(he==NULL){
printf("no address information of %s\n",*argv);
continue;
}
printf("Officaial host name:%s\n",he->h_name);
printf("name aliases:");
for(alias=he->h_aliases;*alias!=NULL;alias++)
printf("%s\n",*alias);
printf("\nIP addresses:");
for(alias=he->h_addr_list;*alias!=NULL;alias++)
printf("%s\n",inet_ntoa(*(struct in_addr *)(*alias)));
}
}
目前暂无任何回答
- 0 回答
- 0 关注
- 1691 浏览
添加回答
举报
0/150
提交
取消