note 26641 added to function.gethostbyaddr
| From: | abe at abe2k dot net | Date: | Fri, 08 Nov 2002 00:32:59 +0000 |
| Subject: | note 26641 added to function.gethostbyaddr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39107@lists.php.net to get a copy of this message | ||
gethostbyaddr() doesn't seem to be able to resolve ip6.int
(ipv6) adresses, so I made a function that can, and works
just like the normal gethostbyaddr().
You need dig and ipv6calc, dig should come with most
distributions, if not, install bind from http://www.isc.org.
ipv6calc can be found at http://www.bieringer.de/linux/IPv6/ipv6calc/index.html.
function gethostbyaddr6($ip6) {
$ipv6calc = "/bin/ipv6calc";
$dig = "/usr/bin/dig";
$file = popen($ipv6calc." --in ipv6addr --out revnibbles.int ".escapeshellarg($ip6), r);
$ip = fread($file, 128);
pclose($file);
if ((substr($ip, 0, 5) == "Error") || (!$ip)) return "Address is not a valid IPv6
address";
$file = popen($dig." ptr ".$ip, r);
while (!feof ($file)) {
$buffer = fgets($file, 128);
if (substr($buffer, 0, 1) == ";") continue;
$buffer = explode(" ", $buffer);
if ($buffer[3] == "PTR") {
$host = substr(trim($buffer[4]), 0, -1);
pclose($file);
return $host;
}
}
pclose($file);
return $ip6;
}
echo gethostbyaddr6($_SERVER[REMOTE_ADDR]);
--
http://www.php.net/manual/en/function.gethostbyaddr.php
http://master.php.net/manage/user-notes.php?action=edit+26641
http://master.php.net/manage/user-notes.php?action=delete+26641
http://master.php.net/manage/user-notes.php?action=reject+26641