add plain json output
This commit is contained in:
parent
0e30bf8138
commit
6bddefe8b5
28
src/plain.php
Normal file
28
src/plain.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?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";
|
||||
}
|
||||
|
||||
$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"];
|
||||
|
||||
if ($res["country"] == null) {
|
||||
$res["country"] = "_unknown";
|
||||
}
|
||||
|
||||
if ($asnr["autonomous_system_number"] == null) {
|
||||
$res["asn"] = "No GeoIP entry found, are you new?";
|
||||
}
|
||||
|
||||
print(json_encode($res, JSON_PRETTY_PRINT) . "\n");
|
Loading…
Reference in a new issue