PHPackages                             weijiajia/ip-address - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. weijiajia/ip-address

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

weijiajia/ip-address
====================

IP address information query system, integrating multiple IP geographic location services

1.0.2(1y ago)041MITPHPPHP ^8.2

Since Oct 3Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/jackchang1025/ip-address)[ Packagist](https://packagist.org/packages/weijiajia/ip-address)[ Docs](https://github.com/jackchang1025/ip-address)[ RSS](/packages/weijiajia-ip-address/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Ip Address
==========

[](#ip-address)

Ip Address 是一个 IP 地址信息查询系统,集成了多个 IP 地理位置服务

支持平台
----

[](#支持平台)

- [ip138](http://api.ipshudi.com)
- [pconline](https://whois.pconline.com.cn)

特性
--

[](#特性)

- 支持多个 IP 地理位置服务提供商 (目前支持 ip138 和 pconline)
- 标准化的响应格式
- 灵活的日志记录功能
- 错误处理

要求
--

[](#要求)

- PHP 8.2+
- Composer

安装
--

[](#安装)

通过 Composer 安装:

```
composer require weijiajia/ip-address
```

首先，发布配置文件：

```
php artisan vendor:publish --provider="Weijiajia\IpAddress\IpAddressServiceProvider"
```

这将在 `config/http-proxy-manager.php` 创建配置文件。

使用方法
----

[](#使用方法)

### 使用 pconline

[](#使用-pconline)

```
use Weijiajia\IpConnector;
use Weijiajia\Requests\PconLineRequest;

$connector = new IpConnector();

// 可选: 设置日志
$logger = new YourLoggerImplementation(); // 替换为您的实际日志实现
$connector->withLogger($logger);

//可选:设置超时
$connector->config()->add('timeout',30);

$request = new PconLineRequest('your ip address');
$response = $connector->send($request);

$ipInfo = $response->dto();
echo $ipInfo->getCity(); // 输出城市信息
echo $ipInfo->getAddr(); // 输出详细地址
```

### 使用 Ip138Request

[](#使用-ip138request)

```
use Weijiajia\IpConnector;
use Weijiajia\Requests\Ip138Request;

$connector = new IpConnector();

$request = new Ip138Request($token, 'your ip address');
$response = $connector->send($request);

$ipInfo = $response->dto();
echo $ipInfo->getCity(); // 输出城市信息
echo $ipInfo->getAddr(); // 输出详细地址
```

### 错误处理

[](#错误处理)

```
use Weijiajia\IpConnector;
use Weijiajia\Requests\PconLineRequest;
use Weijiajia\Exceptions\IpLookupException;

$connector = new IpConnector();

try {
    $request = new PconLineRequest('invalid_ip');
    $response = $connector->send($request);
    $ipInfo = $response->dto();
} catch (IpLookupException $e) {
    echo "IP 查询失败: " . $e->getMessage();
} catch (\Exception $e) {
    echo "发生错误: " . $e->getMessage();
}
```

扩展
--

[](#扩展)

要添加新的 IP 地理位置服务提供商,只需创建一个新的 Request 类并实现必要的方法。例如:

```
namespace Weijiajia\Requests;

use Saloon\Enums\Method;
use Saloon\Http\Request;

class NewProviderRequest extends Request
{
    protected Method $method = Method::GET;

    public function __construct(protected string $ip)
    {
    }

    public function resolveEndpoint(): string
    {
        return 'https://api.newprovider.com/ip-lookup';
    }

    // 实现必要的方法...
    public function createDtoFromResponse(Response $response): IpResponse
    {
        $json = $response->json();

        return new IpResponse([
            'city' => $response->json('city'),
            'addr' => $response->json('addr'),
            'ip'   => $response->json('ip'),
            ...
        ]);
    }
}

// 使用新的 IP 地理位置服务提供商
$connector = new IpConnector();

$request = new NewProviderRequest('your ip address');
$response = $connector->send($request);

$ipInfo = $response->dto();
echo $ipInfo->getCity(); // 输出城市信息
echo $ipInfo->getAddr(); // 输出详细地址
```

参考文档
----

[](#参考文档)

- [saloon 文档](https://docs.saloon.dev/)

贡献指南
----

[](#贡献指南)

我们欢迎并感谢任何形式的贡献。以下是一些贡献的方式:

1. 报告 Bug
2. 提交功能请求
3. 提交代码改进
4. 改进文档

### 提交 Pull Request

[](#提交-pull-request)

1. Fork 本仓库
2. 创建您的特性分支 (`git checkout -b feature/AmazingFeature`)
3. 提交您的改动 (`git commit -m 'Add some AmazingFeature'`)
4. 推送到分支 (`git push origin feature/AmazingFeature`)
5. 创建一个 Pull Request

许可证
---

[](#许可证)

IP Address 是开源软件,基于 [MIT 许可证](LICENSE.md)。

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance44

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

3

Last Release

575d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/636557533fde1107bb301eca908de1c17c9ea7073d5c9c0fbad725ccd0800bde?d=identicon)[jackchang1025](/maintainers/jackchang1025)

---

Top Contributors

[![422066139](https://avatars.githubusercontent.com/u/1780162?v=4)](https://github.com/422066139 "422066139 (24 commits)")

---

Tags

ip-addressIP Info

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/weijiajia-ip-address/health.svg)

```
[![Health](https://phpackages.com/badges/weijiajia-ip-address/health.svg)](https://phpackages.com/packages/weijiajia-ip-address)
```

###  Alternatives

[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[in2code/ipandlanguageredirect

Redirects TYPO3 visitors automatic or with a suggestlink to another language and/or root page.

1738.0k](/packages/in2code-ipandlanguageredirect)[worm/getclientiplib

GetClientIp is a lightweight PHP class for get real/original client IP address, without proxy as opera mini and other.

1812.8k1](/packages/worm-getclientiplib)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
