qbcloud / laravel-geoip2
Query the geographical location by IP address.
1.0.0
2024-07-01 03:28 UTC
Requires
- php: >=7.2.5
- geoip2/geoip2: ^2.13
- illuminate/support: ^5.2|^6|^7|^8
This package is auto-updated.
Last update: 2025-03-29 00:54:58 UTC
README
使用Laravel 6.x 以上通过Geoip2的GeoLite2 City、GeoLite2 Country、GeoLite2 ASN查询IP信息。
下载 GeoIP Databases 文件
PS:需要注册官方账号
https://www.maxmind.com/en/accounts/692132/geoip/downloads
用法
composer require qbcloud/laravel-geoip2
发布配置文件:
php artisan vendor:publish --provider="QbCloud\Geoip2\Providers\GeoipServiceProvider"
// config/geoip2.php return [ 'lang' => 'zh-CN', // zh-CN en ru pt-BR ja fr es de 'db_type' => 'city', // city country asn db_type===city则db_path_city必填 db_type===country则db_path_country必填 'db_path_city' => 'geoip2/GeoLite2-City.mmdb', // 以 storage_path() 为根目录 'db_path_country' => 'geoip2/GeoLite2-Country.mmdb', // 以 storage_path() 为根目录 'db_path_asn' => 'geoip2/GeoLite2-ASN.mmdb' // 以 storage_path() 为根目录 ];
use QbCloud\Geoip2\Facades\IPQuery; // 查询 ipv4 或者 ipv6 IPQuery::connect('x.x.x.x'); // 或者 use QbCloud\Geoip2\IPQuery; $client = new IPQuery(); $client->connect('2xx6:4xx0:0:1x3::a0');