From 4e1713bbc5009e40e4251e727f9cd28a97ba7d3d Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 7 Jul 2015 19:43:25 +0100 Subject: [PATCH] Improved the discovery of IP based devices --- includes/discovery/discovery-arp.inc.php | 13 +++---------- includes/discovery/functions.inc.php | 12 +++++++----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/includes/discovery/discovery-arp.inc.php b/includes/discovery/discovery-arp.inc.php index fce4e2f9a6..230752d9ea 100644 --- a/includes/discovery/discovery-arp.inc.php +++ b/includes/discovery/discovery-arp.inc.php @@ -69,17 +69,10 @@ foreach (dbFetchRows($sql, array($deviceid)) as $entry) } arp_discovery_add_cache($ip); - // Log reverse DNS failures so the administrator can take action. $name = gethostbyaddr($ip); - if ($name != $ip) { // gethostbyaddr returns the original argument on failure - echo("+"); - $names[] = $name; - $ips[$name] = $ip; - } - else { - echo("-"); - log_event("ARP discovery of $ip failed due to absent reverse DNS", $deviceid, 'interface', $if); - } + echo("+"); + $names[] = $name; + $ips[$name] = $ip; } echo("\n"); diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index f369fac79b..9aa82d274b 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -22,12 +22,14 @@ function discover_new_device($hostname) } if ($debug) { echo("discovering $dst_host\n"); } $ip = gethostbyname($dst_host); - if ($ip == $dst_host) { - if ($debug) { echo("name lookup of $dst_host failed\n"); } - return FALSE; - } else { - if ($debug) { echo("ip lookup result: $ip\n"); } + if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE) { + // $ip isn't a valid IP so it must be a name. + if ($ip == $dst_host) { + if ($debug) { echo("name lookup of $dst_host failed\n"); } + return FALSE; + } } + if ($debug) { echo("ip lookup result: $ip\n"); } $dst_host = rtrim($dst_host, '.'); // remove trailing dot