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