Files
Froxlor/lib/functions/phphelpers/function.gethostbynamel6.php
Michael Kaufmann 3a3b35b2eb add ipv6 support for resolving nameserver-hostnames
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
2018-11-21 19:26:19 +01:00

34 lines
611 B
PHP

<?php
/**
* ipv6 aware gethostbynamel function
*
* @param string $host
* @param boolean $try_a default true
* @return boolean|array
*/
function gethostbynamel6($host, $try_a = true)
{
$dns6 = dns_get_record($host, DNS_AAAA);
if ($try_a == true) {
$dns4 = dns_get_record($host, DNS_A);
$dns = array_merge($dns4, $dns6);
} else {
$dns = $dns6;
}
$ips = array();
foreach ($dns as $record) {
if ($record["type"] == "A") {
$ips[] = $record["ip"];
}
if ($record["type"] == "AAAA") {
$ips[] = $record["ipv6"];
}
}
if (count($ips) < 1) {
return false;
} else {
return $ips;
}
}