gethost.c
上传用户:gzxinfenfa
上传日期:2015-02-06
资源大小:279k
文件大小:1k
源码类别:

ICQ弱点检测代码

开发平台:

Visual C++

  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <string.h>
  4. #include <netdb.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. int main(int argc,char **argv)
  9. {
  10. struct hostent *host;
  11. int i=0;
  12. int fd;
  13. char buf[256];
  14. if(argc<2)
  15. {
  16. printf("Usage:%s host_namen",argv[0]);
  17. return 1;
  18. }
  19. host = gethostbyname(argv[1]);
  20. if(host == NULL)
  21. {
  22. printf("gethostbyname error:%sn", hstrerror(h_errno));
  23. }
  24. else
  25. {
  26. printf( "h_name:%sn",host->h_name );
  27. printf( "h_length:%dn",host->h_length );
  28. printf( "h_addrtype:%dn",host->h_addrtype);
  29. for(i=0; host->h_aliases[i]!=NULL;i++)
  30. {
  31. printf("h_alias%d:%sn",i+1,host->h_aliases[i]);
  32. }
  33. for(i=0;host->h_addr_list[i]!=NULL;i++)
  34. {
  35. printf("ip%d:%sn",i+1,inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
  36. }
  37. }
  38. struct in_addr addr;
  39. inet_aton("202.117.112.3",&addr);
  40. host = gethostbyaddr((char *)&addr,4,AF_INET);
  41. if(host!=NULL){
  42. printf("h_name:%sn",host->h_name);
  43. }
  44. else
  45. printf("gethostbyname error:%sn",hstrerror(h_errno));
  46. return 0;
  47. }