I am trying to get the IPv6 address of a hostname. For example:
// Compressed $IPv6 = "2001:4998:c:a06::2:4008"; // Expanded $IPv6 = "2001:4998:000c:0a06:0000:0000:0002:4008";
I first get the hostname by:
$hostname = gethostbyname("2001:4998:c:a06::2:4008"); // ---> ir1.fp.vip.gq1.yahoo.com
$hostname = gethostbyname("2001:4998:000c:0a06:0000:0000:0002:4008"); // ---> ir1.fp.vip.gq1.yahoo.com
Whether I use the compressed or full version of IPv6 I get the same hostname. Now I use the hostname to get the IP address:
$ipaddress = gethostbyaddr("ir1.fp.vip.gq1.yahoo.com"); // ---> 126.96.36.199
This is the IPv4 address. I find the
DNS_AAAA record by:
$recordAAAA = dns_get_record("ir1.fp.vip.gq1.yahoo.com", DNS_AAAA);
Which provides me the output:
Array (  => Array ( [host] => ir1.fp.vip.gq1.yahoo.com [class] => IN [ttl] => 300 [type] => AAAA [ipv6] => 2001:4998:c:a06::2:4008 ) )
I can definitely see the IPv6 compressed address. Having to use the
DNS_AAAA record is not very efficient.
Is there any way to use the
gethostbyaddr() function somehow to get the IPv6 address? Or what is the most efficient way to get the IPv6 address from the hostname?