#!/tool/pandora64/bin/perl5.8.8 use Net::DNS; use Data::Dumper; use strict; use warnings; my $host = $ARGV[0]; my @domains; open(RESOLV, "/etc/resolv.conf") or die("couldn't open /etc/resolv.conf for reading!"); while() { next unless /^search\s+(.*)/; my $str = $1; @domains = split(/\s+/, $str); } close RESOLV; my $res = new Net::DNS::Resolver; $res->debug(1); # Remove all subdomain stuff $host =~ s/\..*//g; # Now figure out the FQDN by choosing from the entries in resolv.conf. my ( $fqhost, $query ); foreach(@domains) { print "query -> $host.$_\n"; $query = $res->query("$host.$_"); if($query) { $fqhost = $host . "." . $_; last; } } unless(defined $fqhost) { print Dumper( \@domains ); print Dumper( \$query ); # If we can't resolve the IP for a given hostname, # we skip that host completely. die "WARNING: Skipping host: $host, query: $query -- no DNS entry!"; }