home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SATAN11.ZIP / PERL / GETFQDN.PL < prev    next >
Text File  |  1995-04-11  |  1KB  |  52 lines

  1. #
  2. # Look up a host name the hard way, using nsloookup. Don't rely on the
  3. # gethostbyname() library routine, as there are too many broken NIS
  4. # setups.  Return an empty string in case of errors.
  5. #
  6. # Stand-alone usage: getfqdn.pl hostname.
  7. #
  8. # version 1, Tue Mar 21 19:31:03 1995, last mod by wietse
  9. #
  10. require 'config/paths.pl';
  11. require 'config/satan.cf';
  12.  
  13. sub getfqdn {
  14.     local($host) = @_;
  15.     local($result, $temp);
  16.  
  17.     if ($host =~ /^[0-9.]+$/) {
  18.         return $host unless ($temp = &get_host_name($host));
  19.         $host = $temp;
  20.     }
  21.     if ($dont_use_nslookup) {
  22.         return &get_host_name($host);
  23.     }
  24.  
  25.     if (!exists($getfqdn_cache{$host})) {
  26.         open(NSLOOKUP, "$NSLOOKUP 2>/dev/null <<EOF\n$host\nEOF|") 
  27.             || die "cannot run $NSLOOKUP: $!";
  28.         $result = "";
  29.         while(<NSLOOKUP>) {
  30.             if (/name:\s+(\S+)/i) {
  31.                 ($result = $1) =~ tr /A-Z/a-z/;
  32.                 last;
  33.             }
  34.         }
  35.         close(NSLOOKUP);
  36.         $getfqdn_cache{$host} = $result;
  37.     }
  38.     return($getfqdn_cache{$host});
  39. }
  40.  
  41. #
  42. # Some scaffolding code for stand-alone testing.
  43. #
  44. if ($running_under_satan == 0) {
  45.     $running_under_satan = 1;
  46.     require 'perl/get_host.pl';
  47.     $host = &getfqdn($ARGV[0]);
  48.     print "$host\n";
  49. }
  50.  
  51. 1;
  52.