ip6.biz/src/hostname.php

36 lines
653 B
PHP
Raw Normal View History

2021-05-04 23:45:21 +02:00
<?php
header('Content-Type: application/json');
$ip = $_SERVER['REMOTE_ADDR'];
if (substr($ip, 0, 9) === "10.23.42.") {
2022-07-02 21:36:31 +02:00
$ip = "88.99.139.92";
2021-05-04 23:45:21 +02:00
}
$ip = escapeshellcmd($ip);
print(json_encode(gethost($ip)));
function gethost($ip)
{
$ires = array();
$host = `host -s -W 5 $ip`;
2021-09-03 03:42:00 +02:00
$host = explode(' ', trim(trim($host), '.'));
$host = ($host ? end($host) : $ip);
2021-05-04 23:45:21 +02:00
$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;
}