#!/usr/bin/perl -w # #NAME # Hosts - generats hosts-file entries from nslookup # #SYNOPSIS # Hosts host... # #DESCRIPTION # This uses nslookup to get addresses for the named hosts, and # generates output that can be added to /etc/hosts to give the same # information locally. # #REQUIRES # nslookup(1) # #OPTIONS # none # #BUGS # Sometimes nslookup is very slow. # #SEE ALSO # Addr, NSlookup, nslookup, /etc/hosts # #AUTHOR # John Chambers $exitstat = 1; for $h (@ARGV) { @rsp = `nslookup $h`; $state = 'INIT'; for $l (@rsp) { if ($l =~ /^Server:/) { $state = 'SRVR'; } elsif ($l =~ /^Name:\s*(.*)\s*$/) { $state = 'NAME'; $name = lc($1); } elsif ($l =~ /^Address:\s*(.*)\s*$/) { if ($state eq 'NAME') { print "$1\t$name\n"; $exitstat = 0; } } else { } } } exit $exitstat;