home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / sgi / admin / 28 < prev    next >
Encoding:
Text File  |  1992-12-16  |  2.0 KB  |  98 lines

  1. Newsgroups: comp.sys.sgi.admin
  2. Path: sparky!uunet!mcsun!sun4nl!dutrun!donau!dirk
  3. From: Dirk.Wisse@dnpap.et.tudelft.nl (Dirk Wisse)
  4. Subject: Re: system names from IP
  5. Message-ID: <dirk.724509354@dutepp18>
  6. Sender: news@donau.et.tudelft.nl (UseNet News System)
  7. Nntp-Posting-Host: dutepp18.et.tudelft.nl
  8. Organization: Delft University of Technology, Dept. of Electrical Engineering
  9. References: <1992Dec14.172453.26933@den.mmc.com> <hofmann.724433734@nova>
  10. Date: Wed, 16 Dec 1992 12:35:54 GMT
  11. Lines: 85
  12.  
  13. hofmann@nova.tat.physik.uni-tuebingen.de (Bernhard Hofmann) writes:
  14.  
  15. >beck@enterprise.den.mmc.com (Fred R. Beck) writes:
  16.  
  17. >>Howdy!
  18.  
  19. >>Has anyone out there ever tried to resolve a system name
  20. >>from an IP number?
  21.  
  22. >Have a look at the man page of gethostbyaddr. A simple C code should
  23. >do the job.
  24.  
  25. Like this:
  26.  
  27. ------- cut here ----------
  28.  
  29.  
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <sys/types.h>
  33. #include <sys/time.h>
  34. #include <sys/ioctl.h>
  35. #include <sys/errno.h>
  36. #include <netdb.h>
  37.  
  38.  
  39. void main (int argc, char **argv)
  40. {
  41.         
  42.     struct hostent
  43.         *ent;
  44.     long unsigned
  45.         adr;
  46.     char *p;
  47.  
  48.     if (argc!=2)
  49.     {
  50.          fprintf(stderr,"\nusage: %s <IP name or address>\n",argv[0]);
  51.          exit(1);
  52.     }
  53.  
  54.     ent=gethostbyname (argv[1]);
  55.     if (ent==0)
  56.     {
  57.         adr=inet_addr(argv[1]);            
  58.         ent=gethostbyaddr ((char *)&adr,4,2);
  59.     }
  60.  
  61.     if (ent==0)
  62.     {
  63.     fprintf(stderr,"\nno such name or address\n");
  64.       exit(1);
  65.     }
  66.     printf("Official name    : %s\n",ent->h_name);
  67.     while ((p= *(ent->h_aliases)) != NULL)
  68.     {
  69.     printf ("Alias        : %s\n", p);
  70.     ent->h_aliases++;
  71.     }
  72.     while ((p= *(ent->h_addr_list)) != NULL)
  73.     {
  74.     printf("Address        : %s ( 0x%08lx )\n", inet_ntoa((struct in_addr *)p), *(unsigned long *)p);
  75.         ent->h_addr_list++;
  76.     }
  77. }
  78.  
  79.  
  80. ------- cut here ----------
  81.  
  82.  
  83. You specify an IP hostname or an IP address on the commandline. You get
  84. all the information there is in the entry form the DNS.
  85.  
  86.  
  87. >Have fun,
  88. >Bernhard
  89.  
  90.  
  91. The same from me,
  92. Dirk
  93. --
  94. --
  95. Dirk Wisse
  96.  
  97. Internet: Dirk.Wisse@dnpap.et.tudelft.nl
  98.