g_speran has asked for the wisdom of the Perl Monks concerning the following question:
Hello Perl Monks, The code I have below, works fine for all intended purposes of what specifically needs to be accomplish. However, there is one item that i also would like to incorporate but not sure how or if it is possible. Is, there a way below, to incorporate the ability to specify one or more DNS resolvers to resolve the lookups against?
use Net::hostent; use Socket; use Data::Dumper::Simple; $IP='192.168.50.70'; $resolver='192.168.10.99'; Host_IP (); print "\n\n\n\n"; Host_Name ('garytest'); sub Host_IP () { $address=inet_aton($IP); if($hent = gethostbyaddr($address)) { $name = $hent->name; $aliases = $hent->aliases; $RESULT="NSLOOKUP by IP: $IP => $name"; print $RESULT; if (scalar(@{$aliases} > 1)) { $RESULT=" Multiple hostnames are being returned. Correc +t DNS\n"; $RESULT = $RESULT . " \taddress $IP has the following na +mes:\n"; $RESULT = $RESULT . "\t$_\n" for ($name, @{$aliases}); print $RESULT; } }else { $RESULT= "NSLOOKUP by IP: $IP => #### UNRESOLVABLE ####"; print $RESULT; } } sub Host_Name () { $name=shift; if ($hent = gethostbyname($name)) { $name2 = $hent->name; # in case different $addr_ref = $hent->addr_list; @addresses = map { inet_ntoa($_) } @$addr_ref; push(@all_addresses,@addresses); $RESULT= "NSLOOKUP by Name: $name => $name2 => " . join(', ', +sort(@addresses)) ; print $RESULT; if (scalar(@addresses) > 1) { $RESULT="\n Multiple IP Address being returned. Correct + DNS"; print $RESULT; } } else{ $RESULT= "NSLOOKUP by Name: $name => #### UNRESOLVABLE ####"; print $RESULT; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Specifying a DNS resolver
by Fletch (Bishop) on Apr 03, 2023 at 13:29 UTC | |
|
Re: Specifying a DNS resolver
by haukex (Archbishop) on Apr 03, 2023 at 17:26 UTC | |
by Anonymous Monk on Apr 03, 2023 at 17:35 UTC | |
|
Re: Specifying a DNS resolver
by g_speran (Scribe) on Apr 07, 2023 at 02:18 UTC | |
by hippo (Archbishop) on Apr 07, 2023 at 15:01 UTC | |
by Anonymous Monk on Apr 07, 2023 at 15:47 UTC |