mixed im_status(string host) -- Attempt to geolocate a host, using the hostip.info service
<?php |
This will output:
Danmark |
Published under the terms of the BSD License
<?php
function ipinfo($host) {
$return = array();
if (preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $host)) {
$ip = $host;
}
else {
$ip = gethostbyname($host);
if ($ip == $host) {
return false;
}
}
$return['ip'] = $ip;
$return['hostname'] = gethostbyaddr($ip);
$lookup = @file("http://api.hostip.info/get_html.php?ip=$ip&position=true");
if ($lookup === false) {
return false;
}
$country = ucfirst(strtolower(substr($lookup[0], 9, -6)));
$cc = strtolower(substr($lookup[0], -4, 2));
if ($cc != 'xx') {
$return['country'] = $country;
$return['cc'] = $cc;
if (trim($lookup[1]) != "City: (Unknown city)") {
$return['city'] = substr(trim($lookup[1]), 6);
}
if (trim($lookup[2]) != "Latitude:") {
$return['latitude'] = substr(trim($lookup[2]), 10);
$return['longitude'] = substr(trim($lookup[3]), 11);
}
}
else {
return false;
}
return $return;
}
?>
Last updated: Sat Jun 14 20:02:45 CEST 2008