guibranco/ipquery-php
最新稳定版本:v1.1.70
Composer 安装命令:
composer require guibranco/ipquery-php
包简介
A lightweight and efficient PHP library for querying IP data from the IpQuery API.
README 文档
README
A lightweight and efficient PHP library for querying IP data from the IpQuery API.
Easily retrieve detailed information about IP addresses, including ISP details, geolocation, and risk analysis.
Features ✨
- Retrieve your public IP information with ease.
- Query detailed data for single or multiple IP addresses.
- Parse JSON responses into strongly-typed PHP objects.
- Simple integration using pure PHP and cURL.
Installation 📦
You can install the library using Composer:
composer require guibranco/ipquery-php
Usage 🚀
Get your public IP data
require_once 'vendor/autoload.php'; use GuiBranco\IpQuery\IpQueryClient; $client = new IpQueryClient(); try { $ipQuery = $client->getMyIpData(); echo "My IP: {$ipQuery->ip}" . PHP_EOL; echo "ISP: {$ipQuery->isp->org}" . PHP_EOL; } catch (Exception $e) { echo "Error: " . $e->getMessage() . PHP_EOL; }
Get data for a specific IP
$ipData = $client->getIpData('8.8.8.8'); echo "IP: {$ipData->ip}" . PHP_EOL; echo "Location: {$ipData->location->city}, {$ipData->location->country}" . PHP_EOL;
Get data for multiple IPs
$multipleIpData = $client->getMultipleIpData(['8.8.8.8', '8.8.4.4']); foreach ($multipleIpData as $ip) { echo "IP: {$ip->ip}, Org: {$ip->isp->org}" . PHP_EOL; }
Response Mapping 🗺️
The library parses JSON responses into the following class structure:
IpQueryResponse
class IpQueryResponse { public string $ip; public Isp $isp; public Location $location; public Risk $risk; }
Isp
class Isp { public string $asn; public string $org; public string $isp; }
Location
class Location { public string $country; public string $country_code; public string $city; public string $state; public string $zipcode; public float $latitude; public float $longitude; public string $timezone; public string $localtime; }
Risk
class Risk { public bool $is_mobile; public bool $is_vpn; public bool $is_tor; public bool $is_proxy; public bool $is_datacenter; public int $risk_score; }
Requirements 🛠️
- PHP 8.2 or newer
- cURL extension enabled
Running Tests 🧪
This project uses PhpUnit 11 for unit tests. To run the tests, execute:
./vendor/bin/phpunit
Contribution 🤝
Contributions are welcome! Please read the CONTRIBUTING.md file for details on the process.
Feel free to open issues or submit pull requests to improve the library.
License 📜
This project is licensed under the MIT License.
Examples 📚
Explore the examples/ directory for more code samples and ideas.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-25