26 lines
645 B
PHP
26 lines
645 B
PHP
<?php
|
|
use MaxMind\Db\Reader;
|
|
header('Content-Type: application/json');
|
|
|
|
$ip = $_SERVER['REMOTE_ADDR'];
|
|
if (substr($ip, 0, 9) === "10.23.42.") {
|
|
$ip = "116.202.163.154";
|
|
}
|
|
|
|
$hostname = gethostbyaddr($ip);
|
|
$res = array();
|
|
$res["address"] = $ip;
|
|
if ($ip !== $hostname){
|
|
$res["hostname"] = $hostname;
|
|
}
|
|
$countrydb = '/var/lib/GeoIP/GeoLite2-Country.mmdb';
|
|
$asndb = '/var/lib/GeoIP/GeoLite2-ASN.mmdb';
|
|
|
|
$asnr = (new Reader($asndb))->get($ip);
|
|
|
|
$res["country"] = (new Reader($countrydb))->get($ip)["country"]["iso_code"];
|
|
$res["asn"] = "AS".$asnr["autonomous_system_number"]." ".$asnr["autonomous_system_organization"];
|
|
|
|
|
|
print(json_encode($res));
|