From 8dc54b79e3125c1e59e9066afdcf0da8dcf5db8f Mon Sep 17 00:00:00 2001 From: Guillaume Mazoyer Date: Wed, 6 Aug 2014 01:14:32 +0200 Subject: Add ping/traceroute for FQDN on BIRD and Quagga. Basically this can work with all Linux boxes. It gets A and AAAA records from DNS and decide if it can uses IPv6 or IPv4 to ping or to traceroute. IPv6 is always preferred of course. --- includes/utils.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'includes/utils.php') diff --git a/includes/utils.php b/includes/utils.php index b6fc061..ee0c367 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -89,6 +89,46 @@ function match_aspath_regex($aspath_regex) { return true; } +function fqdn_to_ip_address($fqdn) { + $dns_record = dns_get_record($fqdn, DNS_A + DNS_AAAA); + + // No DNS record found + if (!$dns_record) { + return false; + } + + $records_nb = count($dns_record); + + // Only one record found + if ($records_nb == 1) { + if ($dns_record[0]['type'] == 'AAAA') { + return $dns_record[0]['ipv6']; + } else if ($dns_record[0]['type'] == 'A') { + return $dns_record[0]['ip']; + } else { + return false; + } + } + + // Several records found + if ($records_nb > 1) { + // TODO: this could probably be more optimal + foreach ($dns_record as $record) { + if ($record['type'] == 'AAAA') { + return $record['ipv6']; + } + } + + foreach ($dns_record as $record) { + if ($record['type'] == 'AAA') { + return $record['ipv4']; + } + } + + return false; + } +} + function log_to_file($log) { global $config; -- cgit v1.2.3