PHPackages                             duc\_cnzj/ip - 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. duc\_cnzj/ip

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

duc\_cnzj/ip
============

A SDK for ip.

v1.1.9(7y ago)3514MITPHPCI failing

Since Nov 6Pushed 6y agoCompare

[ Source](https://github.com/DuC-cnZj/ip)[ Packagist](https://packagist.org/packages/duc_cnzj/ip)[ RSS](/packages/duc-cnzj-ip/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (6)Dependencies (3)Versions (25)Used By (0)

ip
==

[](#ip)

A SDK for ip.

[![Build Status](https://camo.githubusercontent.com/125467512b1e0858ded51b64911cebd8ecd307b8c6f19616712c9928179a3b61/68747470733a2f2f7472617669732d63692e636f6d2f4475432d636e5a6a2f69702e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/DuC-cnZj/ip)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/853c218063bbc6c606997f14d57a3f546d36a4ce833650ccc4ea59fe27b654a2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4475432d636e5a6a2f69702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/DuC-cnZj/ip/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/fc325e6500fc14168b45b0669b4f7b7c099f99895fa4c5fbaaa27e92a8a308c5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4475432d636e5a6a2f69702f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/DuC-cnZj/ip/?branch=master)[![StyleCI build status](https://camo.githubusercontent.com/c2d385cf1c96bc09db1f297c390e2bbcb62633e5ad68db6841b3c51fc524d320/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3135363335363132362f736869656c64)](https://camo.githubusercontent.com/c2d385cf1c96bc09db1f297c390e2bbcb62633e5ad68db6841b3c51fc524d320/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3135363335363132362f736869656c64)

Support
-------

[](#support)

- [baidu api](http://lbsyun.baidu.com/index.php?title=webapi/ip-api)
- taobao api
- [ali api](https://market.aliyun.com/products/57002002/cmapi018957.html?spm=5176.730005.productlist.d_cmapi018957.6f613524XYMOwf&innerSource=search_ip#sku=yuncode1295700000)
- [tencent api](https://lbs.qq.com/webservice_v1/guide-ip.html)

Installing
----------

[](#installing)

```
composer require duc_cnzj/ip
```

Usage
-----

[](#usage)

```
$client = new IpClient();

$client->setIp('xxx.xxx.xxx.xxx')->getCity();
$client->setIp('xxx.xxx.xxx.xxx')->getCountry();
$client->setIp('xxx.xxx.xxx.xxx')->getRegion();
$client->setIp('xxx.xxx.xxx.xxx')->getIp();

# or
$client->setIp('xxx.xxx.xxx.xxx');
$client->getCity();
$client->city;

# use Provider (baidu, taobao, ali)
$client = new IpClient();

# if use baidu api, you need provide ak secret.
$client->useProvider('baidu')
    ->setProviderConfig('baidu', ['ak' => 'xxxxxxxxxxxx']);
# or
$client->useProvider('baidu')
    ->setProviderConfig('baidu', 'xxxxxxxxxxxx');

# if use tencent api, you need provide ak secret.
$client->useProvider('tencent')
    ->setProviderConfig('tencent', ['key' => 'xxxxxxxxxxxx']);
# or
$client->useProvider('tencent')
    ->setProviderConfig('tencent', 'xxxxxxxxxxxx');

# mutil set/get configs
$client->setConfigs(['ali' => 'xxxxx', 'baidu' => 'xxxxx']);
$client->getConfigs('ali', 'baidu');

# if use ali api, you need provide ak secret.
$client->useProvider('ali')
    ->setProviderConfig('ali', ['app_code' => 'xxxxxxxxxxxx']);

# if use taobao.
$client->useProvider('taobao');

# default use all provider. if you want use all, pls set secret for each provider.
$client->setProviderConfig('baidu', ['ak' => 'xxxxxxxxxxxx']);
$client->setProviderConfig('ali', 'xxxxxxxxxxxx');

# package will try 3 times when provider response error. use try method to reset tryTimes.
$client->setIp('xxx.xxx.xxx.xxx')->try(10);

# in laravel
 $client = app('ip');
```

extra property

```
# baidu/ali/tencent return point_x and point_y, so you can:
$client->useProvider('baidu')
    ->setProviderConfig('baidu', ['ak' => 'xxxxxxxxxxxx']);

$client->useProvider('ali')
    ->setProviderConfig('ali', ['app_code' => 'xxxxxxxxxxxx']);

$client->useProvider('tencent')
    ->setProviderConfig('tencent', 'xxxxxxxxxxxx');

$client->getPointX();
$client->getPointY();

# taobao return isp, so u can:

$client->useProvider('taobao')
    ->setIp('xxx.xxx.xxx.xxx')
    ->getIsp();
```

when getXXX() false it will return null, u can use `$client->getErrors()` get error info;

alias

```
$client->use('taobao', 'baidu'); # It will be executed in the order you passed it in
# Equals to
$client->useProvider('taobao', 'baidu');
```

other methods

```
$client->clearUse(); # will clear providers;

# custom your instance. need implement DucCnzj\Ip\Imp\IpImp, Object or String.
# if it dont need secret, pls set the third parameter false;
$client->bind('taobao', $taobao);

# set custom CacheStore. default is ArrayStore. need implement DucCnzj\Ip\Imp\CacheStoreImp;
$client->setCacheStore($store);
```

License
-------

[](#license)

MIT

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity71

Established project with proven stability

 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 ~7 days

Recently: every ~22 days

Total

24

Last Release

2584d ago

Major Versions

v0.0.3 → v1.0.02019-01-09

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23514869?v=4)[duc](/maintainers/DuC-cnZj)[@duc-cnzj](https://github.com/duc-cnzj)

---

Top Contributors

[![duc-cnzj](https://avatars.githubusercontent.com/u/23514869?v=4)](https://github.com/duc-cnzj "duc-cnzj (65 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/duc-cnzj-ip/health.svg)

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

###  Alternatives

[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[dhlparcel/magento2-plugin

DHL Parcel plugin for Magento 2

11180.5k2](/packages/dhlparcel-magento2-plugin)[aedart/athenaeum

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

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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