-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlookup.php
More file actions
35 lines (27 loc) · 903 Bytes
/
lookup.php
File metadata and controls
35 lines (27 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
header('Content-type: application/json');
if (is_file(__DIR__ . "/vendor/autoload.php")) {
// Dependencies installed via composer
require(__DIR__ . "/vendor/autoload.php");
} elseif (is_file('/usr/share/php/GeoIP2/autoload.php')) {
// Dependencies installed via Fedora autoloader
require('/usr/share/php/GeoIP2/autoload.php');
} else {
http_response_code(501);
exit;
}
use GeoIp2\Database\Reader AS GeoIP2;
use GeoIp2\Exception\AddressNotFoundException;
$Return = [];
$GeoIP = new GeoIP2('/usr/share/GeoIP/dbip-country-lite.mmdb');
if (isset($_POST['ip']) && is_array($_POST['ip'])) {
foreach ($_POST['ip'] as $IP) {
try {
$Return[$IP] = strtolower($GeoIP->country($IP)->country->isoCode);
} catch (AddressNotFoundException $e) {
$Return[$IP] = 'un';
}
}
}
echo json_encode($Return);