From fd996f07fae4b93341695fd18cdd02311dd047e1 Mon Sep 17 00:00:00 2001 From: IP2Location Date: Mon, 4 Sep 2023 14:37:33 +0800 Subject: [PATCH] added ip2locationio service to geo middleware --- src/Config/firewall.php | 2 +- src/Middleware/Geo.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Config/firewall.php b/src/Config/firewall.php index 420afc8..77a9e16 100644 --- a/src/Config/firewall.php +++ b/src/Config/firewall.php @@ -172,7 +172,7 @@ 'block' => [], // i.e. 'London' ], - // ipapi, extremeiplookup, ipstack, ipdata, ipinfo, ipregistry + // ipapi, extremeiplookup, ipstack, ipdata, ipinfo, ipregistry, ip2locationio 'service' => 'ipapi', 'auto_block' => [ diff --git a/src/Middleware/Geo.php b/src/Middleware/Geo.php index 3be56fa..0f12f67 100644 --- a/src/Middleware/Geo.php +++ b/src/Middleware/Geo.php @@ -182,6 +182,30 @@ public function ipregistry($location) return $location; } + public function ip2locationio($location) + { + $url = 'https://api.ip2location.io/?ip=' . $this->ip() . '&key=' . env('IP2LOCATIONIO_KEY'); + + $response = $this->getResponse($url); + + if (! is_object($response) || empty($response->location)) { + return false; + } + + $location->country = $response->country_name; + $location->country_code = $response->country_code; + $location->region = $response->region_name; + $location->city = $response->city_name; + $location->latitude = $response->latitude; + $location->longitude = $response->longitude; + $location->zipcode = $response->zip_code; + $location->timezone = $response->time_zone; + $location->asn = $response->asn; + $location->as = $response->as; + + return $location; + } + protected function getResponse($url) { try {