ip6.biz/src/hostname.php

36 lines
653 B
PHP

<?php
header('Content-Type: application/json');
$ip = $_SERVER['REMOTE_ADDR'];
if (substr($ip, 0, 9) === "10.23.42.") {
$ip = "88.99.139.92";
}
$ip = escapeshellcmd($ip);
print(json_encode(gethost($ip)));
function gethost($ip)
{
$ires = array();
$host = `host -s -W 5 $ip`;
$host = explode(' ', trim(trim($host), '.'));
$host = ($host ? end($host) : $ip);
$ires = array();
if(in_array($host, Array('reached', 'record', '3(NXDOMAIN)')))
{
$ires["status"] = "none";
}
else if (in_array( $host, Array('2(SERVFAIL)'))){
$ires["status"] = "servfail";
}
else
{
$ires["status"] = "ok";
$ires["response"] = $host;
}
return $ires;
}