chrisullyott / php-ip-api
ip-api.com 的 PHP 封装。
v1.0.1
2020-08-16 00:29 UTC
Requires
- php: >=5.4
- rmccue/requests: ^1.7
Requires (Dev)
README
PHP IP API
从 ip-api.com 获取 IP 地址的地理位置数据。
安装
$ composer require chrisullyott/php-ip-api
实例化
$api = new ChrisUllyott\IpApi(); // Set output language and fields (optional) $api->setLanguage('en'); $api->setFields(['query', 'country', 'city']);
请求一个
$response = $api->get('91.198.174.192'); print_r($response);
stdClass Object ( [country] => Netherlands [city] => Amsterdam [query] => 91.198.174.192 )
请求多个
$ips = [ '100.142.29.254', '100.142.39.218' ]; $response = $api->get($ips); print_r($response);
Array ( [0] => stdClass Object ( [country] => United States [city] => Chicago [query] => 100.142.29.254 ) [1] => stdClass Object ( [country] => United States [city] => Chicago [query] => 100.142.39.218 ) )
从文件中请求(创建 CSV)
使用以换行符分隔的 IP 地址列表,将构建一个包含响应数据的 CSV 文件。
$file = 'ips.txt'; $list = new ChrisUllyott\IpApiList($file); $list->setFields(['query', 'country', 'city']); $list->build();