#!/usr/bin/perl # Addr host... # NSlookup host... # - - - - - - - - - - - - - - - - - - - - - - - - - - - # # This script uses nslookup to get the IP addresses for # # one or more hosts. It strips away all of nslookup's # # excess verbiage, and outputs just the IP address(es). # # Exit status is 0 if at least one IP address is found, # # and 1 if not; STDERR output is trashed. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - # open(STDERR,">/dev/null"); $status = 1; host: foreach $h (@ARGV) { $flag = 0; open(N,"nslookup $h |") || die "$0: Can't exec nslookup [$!]\n"; line: while ($l = ) { if ($l =~ /\s$h\b/) { $flag = 1; next line; } while ($flag && ($l =~ s/(\d+\.\d+\.\d+\.\d+)//)) { print "$1\n"; $status = 0; # next host; } } } exit $status;