ip6.biz/src/info.php

29 lines
721 B
PHP
Raw Normal View History

2021-05-02 20:43:48 +02:00
<?php
use MaxMind\Db\Reader;
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-02 20:43:48 +02:00
}
$res = array();
$res["address"] = $ip;
$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"];
2021-05-03 09:28:30 +02:00
if ($res["country"] == null) {
$res["country"] = "_unknown";
}
if ($asnr["autonomous_system_number"] == null) {
$res["asn"] = "No GeoIP entry found, are you new?";
}
2021-05-02 20:43:48 +02:00
print(json_encode($res));