home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!ames!data.nas.nasa.gov!ace.nas.nasa.gov!jns
- From: jns@ace.nas.nasa.gov (John N. Stewart)
- Subject: Re: How to find IP name knowing IP adress?
- References: <Test_News.15.725105040@uci.agh.edu.pl> <erl.725122174@powell>
- Sender: news@nas.nasa.gov (News Administrator)
- Organization: NAS, NASA Ames Research Center, Moffett Field, California
- Date: Tue, 29 Dec 92 20:16:49 GMT
- Message-ID: <1992Dec29.201649.826@nas.nasa.gov>
- Lines: 100
-
- In article <erl.725122174@powell> erl@powell.cs.jt.dk (Erik Bruijn Larsen) writes:
- >Test_News@uci.agh.edu.pl (News testing account) writes:
- >
- >
- >> For example : I have adress 149.156.96.9
- >> How to find name of machine ?
- >
- >Try typing:
- >% hostname
- >
- >If you are running NIS and want the name of another host, then type:
- >% ypcat hosts
-
-
- No no no nonononononon. :) YP doesn't always have all
- the hosts, it depends on the implementation at each site. Many folks
- have modified the resolver libraries to ignore the hosts map
- completely, especially on Sun's -- it was a hack, but many of us have
- used it.
-
- Hostname? That won't help either really, it only returns the hostname
- of the current host, or tries to set it for that host.
-
-
- Try: nslookup 128.230.1.55 or the script which is attached.
-
-
- 'das all folx!
-
- -Ace
-
-
- John Stewart (Ace)
- CSS/DSS/Security/Postmaster/NewsAdmin
- NASA Ames Research Center
- (415) 604-4345
-
-
-
-
- #!/usr/nas/bin/perl
- # ipq - Answer one of the two common IP queries
- #
- # Tim Cook, December 1992
-
- $prog = substr ($0, rindex ($0, '/') + 1);
-
-
- if ($#ARGV != 0) {
- die "usage: $prog ( hostname | IP-address )\n"; }
-
-
- if ($ARGV[0] =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
- &address_to_name ($ARGV[0]); }
- else {
- &name_to_address ($ARGV[0]); }
-
- exit (0);
-
-
-
- sub name_to_address {
- local ($name) = shift (@_);
-
- local (@octets);
-
- local ($nam, $aliases, $addrtype, $length, $address) =
- gethostbyname ($name);
-
- if (! length ($address)) {
- die "$prog: no address found for $name\n"; }
-
- @octets = unpack ("CCCC", $address);
-
- print (join ('.', @octets[0..3]), "\n");
- }
-
-
- sub address_to_name {
- local ($address) = shift (@_);
-
- local (@octets);
- local ($name, $aliases, $type, $len, $addr);
- local ($ip_number);
-
- @octets = split ('\.', $address) ;
-
- if ($#octets != 3) {
- die "$prog: IP-address must have four octets\n"; }
-
- $ip_number = pack ("CCCC", @octets[0..3]);
-
- ($name, $aliases, $type, $len, $addr) = gethostbyaddr ($ip_number, 2) ;
-
- if ($name) {
- print ($name, "\n") ; }
- else {
- die "$prog: no host-name found for $address\n"; }
- }
-
-