public function remoteHost()
{
global $injector;
$out = new stdClass();
$dns = $injector->getInstance('Net_DNS2_Resolver');
$old_error = error_reporting(0);
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$remote_path = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$out->addr = $remote_path[0];
$out->proxy = true;
} else {
$out->addr = $_SERVER['REMOTE_ADDR'];
if (!empty($_SERVER['REMOTE_HOST'])) {
$out->host = $_SERVER['REMOTE_HOST'];
}
$out->proxy = false;
}
if ($dns && !isset($out->host)) {
$out->host = $out->addr;
try {
if ($response = $dns->query($out->addr, 'PTR')) {
foreach ($response->answer as $val) {
if (isset($val->ptrdname)) {
$out->host = $val->ptrdname;
break;
}
}
}
} catch (Net_DNS2_Exception $e) {
}
} elseif (!isset($out->host)) {
$out->host = gethostbyaddr($out->addr);
}
error_reporting($old_error);
return $out;
}