home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7485 < prev    next >
Encoding:
Internet Message Format  |  1992-12-17  |  2.3 KB

  1. Xref: sparky comp.lang.perl:7485 comp.unix.programmer:5726
  2. Path: sparky!uunet!mcsun!uknet!comlab.ox.ac.uk!mbeattie
  3. From: mbeattie@black.ox.ac.uk (Malcolm Beattie)
  4. Newsgroups: comp.lang.perl,comp.unix.programmer
  5. Subject: Re: Get hostname from IP address
  6. Message-ID: <1992Dec17.172241.26541@black.ox.ac.uk>
  7. Date: 17 Dec 92 17:22:41 GMT
  8. References: <1992Dec13.180845.28960@hyphen.com> <1gj9afINN47k@mimas.cc.deakin.OZ.AU> <1992Dec16.015357.10437@hyphen.com>
  9. Organization: Oxford University Computing Service, 13 Banbury Rd, Oxford, U
  10. Lines: 43
  11. Originator: mbeattie@black
  12.  
  13. In article <1992Dec16.015357.10437@hyphen.com> dwight@hyphen.com (Dwight Ernest) writes:
  14. >tim@deakin.OZ.AU (Tim Cook) writes:
  15. >
  16. >>dejesus@archimedes.nwc.navy.mil (Francisco X DeJesus) writes:
  17. >>>
  18. >>> I'd like to find a utility I can call from the command-line with an
  19. >>> internet IP address as an argument, and have it return to me the full
  20. >>> hostname related to it. I've looked into the function gethostbyaddr()
  21. >>> but haven't been able to work. I also remember reading about a name-
  22. >>> resolver funtion nres_gethostbyaddr() (sp?), but can't find any
  23. >>> references to it on my system. I'm running SunOS 4.1.2 on a Sparc.
  24. >
  25. >>There Is Always A Simple Perl Script That Will Do It (tm).
  26. >
  27. >>The enclosed Perl script will convert a DNS hostname to an IP address
  28. >>or vice-versa.
  29. >
  30. >50+ lines of perl followed.  Simple?  (grin)  Took me about 15 mins to
  31. >hack up both the C programs posted earlier.  How long did it take you
  32. >to cook the perl?  Just curious.
  33. >
  34.  
  35. It took me only a few minutes yesterday to come up with
  36.  
  37. perl -e 'print ((gethostbyaddr(pack("C4",split(/\./,shift)),2))[0]);'
  38.  
  39. which takes an argument of the form 1.2.3.4 and does
  40. the lookup. I was going to post but aborted it because I
  41. started to blather on about how I'd hard-coded AF_INET
  42. as 2 and how you could require sys/socket.ph if you wanted
  43. and how you could error check if you wanted...
  44.  
  45. Now someone wants quick and short hacks, I've got a good
  46. enough excuse to post :-)
  47.  
  48.  
  49.  
  50.  
  51. -- 
  52. Malcolm Beattie <mbeattie@black.ox.ac.uk> | I'm not a kernel hacker
  53. Oxford University Computing Services      | I'm a kernel hacker's mate
  54. 13 Banbury Road, Oxford, OX2 6NN (U.K.)   | And I'm only hacking kernels
  55. Tel: +44 865 273232 Fax: +44 865 273275   | 'Cos the kernel hacker's late
  56.