home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / question / 15051 < prev    next >
Encoding:
Text File  |  1992-12-30  |  2.6 KB  |  112 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!ames!data.nas.nasa.gov!ace.nas.nasa.gov!jns
  3. From: jns@ace.nas.nasa.gov (John N. Stewart)
  4. Subject: Re: How to find IP name knowing IP adress?
  5. References: <Test_News.15.725105040@uci.agh.edu.pl> <erl.725122174@powell>
  6. Sender: news@nas.nasa.gov (News Administrator)
  7. Organization: NAS, NASA Ames Research Center, Moffett Field, California
  8. Date: Tue, 29 Dec 92 20:16:49 GMT
  9. Message-ID: <1992Dec29.201649.826@nas.nasa.gov>
  10. Lines: 100
  11.  
  12. In article <erl.725122174@powell> erl@powell.cs.jt.dk (Erik Bruijn Larsen) writes:
  13. >Test_News@uci.agh.edu.pl (News testing account) writes:
  14. >
  15. >
  16. >> For example : I have adress 149.156.96.9
  17. >> How to find name of machine ?
  18. >
  19. >Try typing:
  20. >% hostname
  21. >
  22. >If you are running NIS and want the name of another host, then type:
  23. >% ypcat hosts
  24.  
  25.  
  26. No no no nonononononon. :) YP doesn't always have all
  27. the hosts, it depends on the implementation at each site. Many folks
  28. have modified the resolver libraries to ignore the hosts map
  29. completely, especially on Sun's -- it was a hack, but many of us have
  30. used it.
  31.  
  32. Hostname? That won't help either really, it only returns the hostname
  33. of the current host, or tries to set it for that host.
  34.  
  35.  
  36. Try:     nslookup 128.230.1.55 or the script which is attached.
  37.  
  38.  
  39. 'das all folx!
  40.  
  41. -Ace
  42.  
  43.  
  44. John Stewart (Ace)
  45. CSS/DSS/Security/Postmaster/NewsAdmin
  46. NASA Ames Research Center
  47. (415) 604-4345
  48.  
  49.  
  50.  
  51.  
  52. #!/usr/nas/bin/perl
  53. # ipq -    Answer one of the two common IP queries
  54. #
  55. # Tim Cook, December 1992
  56.  
  57. $prog = substr ($0, rindex ($0, '/') + 1);
  58.  
  59.  
  60. if ($#ARGV != 0) {
  61.    die "usage: $prog ( hostname | IP-address )\n"; }
  62.  
  63.  
  64. if ($ARGV[0] =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
  65.    &address_to_name ($ARGV[0]); }
  66. else {
  67.    &name_to_address ($ARGV[0]); }
  68.  
  69. exit (0);
  70.  
  71.  
  72.  
  73. sub name_to_address {
  74.    local ($name) = shift (@_);
  75.  
  76.    local (@octets);
  77.  
  78.    local ($nam, $aliases, $addrtype, $length, $address) =
  79.       gethostbyname ($name); 
  80.  
  81.    if (! length ($address)) {
  82.       die "$prog: no address found for $name\n"; }
  83.  
  84.    @octets = unpack ("CCCC", $address);
  85.  
  86.    print (join ('.', @octets[0..3]), "\n");
  87.    }
  88.  
  89.    
  90. sub address_to_name {
  91.    local ($address) = shift (@_);
  92.  
  93.    local (@octets);
  94.    local ($name, $aliases, $type, $len, $addr);
  95.    local ($ip_number);
  96.  
  97.    @octets = split ('\.', $address) ;
  98.  
  99.    if ($#octets != 3) {
  100.       die "$prog: IP-address must have four octets\n"; }
  101.  
  102.    $ip_number = pack ("CCCC", @octets[0..3]);
  103.  
  104.    ($name, $aliases, $type, $len, $addr) = gethostbyaddr ($ip_number, 2) ;
  105.  
  106.    if ($name) {
  107.       print ($name, "\n") ; }
  108.    else {
  109.       die "$prog: no host-name found for $address\n"; }
  110.    }
  111.  
  112.