qbcloud / laravel-geoip2
Query the geographical location by IP address.
2.0.0
2025-04-10 08:16 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-04-10 08:26:12 UTC
README
使用Laravel 6.x 以上通过Geoip2的GeoLite2 City、GeoLite2 ASN查询IP信息。
下载 GeoIP Databases 文件
PS:需要注册官方账号
https://www.maxmind.com/en/accounts/692132/geoip/downloads
文件放置路径
storage/app/geoip
用法
composer require qbcloud/laravel-geoip2
use QbCloud\Geoip2\Facades\IPQuery; // 查询 ipv4 或者 ipv6 IPQuery::connect('x.x.x.x'); // 格式化地址 IPQuery::format(['中国', '广东', '广东']); // 中国-广东 IPQuery::format(['中国', '广东', '广州']); // 中国-广东-广州 // 查询IP类型 IPQuery::ipType('x.x.x.x'); // IPv4 // 查询是否是有效IP IPQuery::isValid('x.x.x.x'); // false // 或者 use QbCloud\Geoip2\IPQuery; $client = new IPQuery(); $client->connect('2xx6:4xx0:0:1x3::a0');