Bug fixes to discovery; add root_ip handling.
Squashed commit of the following: commitcb6f125c73Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Apr 13 20:26:59 2013 +0100 discover root_ip properly commit8228e73f5bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Apr 13 19:47:23 2013 +0100 better name for util package commit4546036f4fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Apr 13 19:23:55 2013 +0100 bug fixes in getting wireless info commit78554e5516Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Apr 13 19:07:44 2013 +0100 refactor snmp_connect to handle versions and device classes commitca9edd114aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Apr 13 15:23:52 2013 +0100 rename discoverall to discovernew commit1b897e4aeeAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Apr 13 14:51:06 2013 +0100 change debug log tag for store_device commit8a5306e056Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Apr 13 14:50:10 2013 +0100 rename Discover.pm to Device.pm commit3197e38819Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Apr 13 14:48:31 2013 +0100 allow netdisco-do to do all acton
This commit is contained in:
@@ -8,7 +8,7 @@ use Net::DNS;
|
||||
use base 'Exporter';
|
||||
our @EXPORT = ();
|
||||
our @EXPORT_OK = qw/
|
||||
hostname_from_ip
|
||||
hostname_from_ip ipv4_from_hostname
|
||||
/;
|
||||
our %EXPORT_TAGS = (all => \@EXPORT_OK);
|
||||
|
||||
@@ -35,6 +35,7 @@ Returns C<undef> if no PTR record exists for the IP.
|
||||
|
||||
sub hostname_from_ip {
|
||||
my $ip = shift;
|
||||
return unless $ip;
|
||||
|
||||
my $res = Net::DNS::Resolver->new;
|
||||
my $query = $res->search($ip);
|
||||
@@ -49,5 +50,30 @@ sub hostname_from_ip {
|
||||
return undef;
|
||||
}
|
||||
|
||||
=head2 ipv4_from_hostname( $name )
|
||||
|
||||
Given a host name will return the first IPv4 address.
|
||||
|
||||
Returns C<undef> if no A record exists for the name.
|
||||
|
||||
=cut
|
||||
|
||||
sub ipv4_from_hostname {
|
||||
my $name = shift;
|
||||
return unless $name;
|
||||
|
||||
my $res = Net::DNS::Resolver->new;
|
||||
my $query = $res->search($name);
|
||||
|
||||
if ($query) {
|
||||
foreach my $rr ($query->answer) {
|
||||
next unless $rr->type eq "A";
|
||||
return $rr->address;
|
||||
}
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user