PHPackages                             itbdw/ip-database - 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. [Database &amp; ORM](/categories/database)
4. /
5. itbdw/ip-database

ActiveLibrary[Database &amp; ORM](/categories/database)

itbdw/ip-database
=================

IP数据库 IPV4 IPV6（解析为国家、省、市、县、运营商）

3.0.2(2y ago)1.5k123.8k—9.6%265[1 issues](https://github.com/itbdw/ip-database/issues)7MITHTMLPHP \*

Since Jun 10Pushed 2y ago27 watchersCompare

[ Source](https://github.com/itbdw/ip-database)[ Packagist](https://packagist.org/packages/itbdw/ip-database)[ RSS](/packages/itbdw-ip-database/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (10)DependenciesVersions (21)Used By (7)

说明
--

[](#说明)

这套识别程序的数据库是免费IP数据库、IP离线地址库。支持将IP转化为结构化的国家、省、市、县、运营商、地区信息

0，该系统是离线的，代码内已经包含IPV4+IPV6离线包。

1，IPV4数据库基于纯真IP库，IP地址纠错相关和最新地址获取请直接去纯真官网，具体见最下方链接。IPV6数据库见最下方链接。

2，纯真IP识别算法来源网络。

3，结构化程序来自我2012年的脑洞。

纯真IP数据存储时，并不是结构化的，因此 结构化程序 解析出来有误差在所难免，国内 ip 可以识别出省份，基本可以识别出市。运营商、县数据看运气。

使用说明
----

[](#使用说明)

当前版本为3.x（ipv4+ipv6），如需要2.x请访问

目前3.x无缝兼容2.x版本，理论上可直接升级。

```
composer require 'itbdw/ip-database' ^3.0

```

```
//根据实际情况，基本上用框架（如 Laravel）的话不需要手动引入
//require 'vendor/autoload.php';

use itbdw\Ip\IpLocation;

//0配置使用
echo json_encode(IpLocation::getLocation($ip), JSON_UNESCAPED_UNICODE) . "\n";

//支持自定义文件路径
$qqwry_filepath = '/abspath/qqwry.dat';
$ipv6wry_path = '/abspath/ipv6wry.db';
echo json_encode(IpLocation::getLocation($ip, $qqwry_filepath), JSON_UNESCAPED_UNICODE) . "\n";
```

响应
--

[](#响应)

获取成功

```
{
  "ip": "163.177.65.160",
  "country": "中国",
  "province": "广东",
  "city": "深圳市",
  "county": "",
  "isp": "联通",
  "area": "中国广东省深圳市腾讯计算机系统联通节点"
}
```

异常

```
{
  "error": "ip invalid"
}
```

本地测试测试
------

[](#本地测试测试)

```
cd 进入 ip-database 目录 ,composer install

php tests/ip.php

{"ip":"172.217.25.14","country":"美国","province":"","city":"","county":"","area":"美国 Google全球边缘网络","isp":""}
{"ip":"140.205.172.5","country":"中国","province":"上海","city":"","county":"","area":"中国上海 阿里云","isp":""}
{"ip":"123.125.115.110","country":"中国","province":"北京","city":"","county":"","area":"中国北京 北京百度网讯科技有限公司联通节点(BGP)","isp":"联通"}
{"ip":"221.196.0.0","country":"中国","province":"天津","city":"河北区","county":"","area":"中国天津河北区 联通","isp":"联通"}
{"ip":"60.195.153.98","country":"中国","province":"北京","city":"顺义区","county":"","area":"中国北京顺义区 后沙峪金龙网吧","isp":""}
{"ip":"218.193.183.35","country":"中国","province":"上海","city":"","county":"","area":"中国上海 D27-707","isp":""}
{"ip":"210.74.2.227","country":"中国","province":"北京","city":"","county":"","area":"中国北京 实验学院机房","isp":""}
{"ip":"162.105.217.0","country":"中国","province":"北京","city":"","county":"","area":"中国北京 4区-4f","isp":""}
{"ip":"fe80:0000:0001:0000:0440:44ff:1233:5678","country":"局域网","province":"","city":"","county":"","area":"局域网 本地链路单播地址","isp":""}
{"ip":"2409:8900:103f:14f:d7e:cd36:11af:be83","country":"中国","province":"北京","city":"","county":"","area":"中国北京 中国移动CMNET网络","isp":"移动"}

php tests/ip.php -i 58.196.128.0
{"ip":"58.196.128.0","country":"中国","province":"上海","city":"","county":"","area":"中国上海 上海交通大学","isp":""}

php tests/ip.php -i 2409:8a00:6c1d:81c0:51b4:d603:57d1:b5ec
{"ip":"2409:8a00:6c1d:81c0:51b4:d603:57d1:b5ec","country":"中国","province":"北京","city":"","county":"","area":"中国北京 中国移动公众宽带","isp":"移动"}

```

提高下载速度
------

[](#提高下载速度)

建议腾讯云加速

原因 [\#42](https://github.com/itbdw/ip-database/issues/42)

赞助喝口水
-----

[](#赞助喝口水)

这个项目也是多个日夜思考的结果，如果觉得对你有帮助，小手一抖也是感谢的。

 [![](https://camo.githubusercontent.com/2dba8c839eeec5f61a582a89ac442e8181d4e60df716f781ad2231ed5beee5b9/68747470733a2f2f7778312e73696e61696d672e636e2f6d773639302f36623934613265356c7931676c30777a74657670786a323079693161756a77622e6a7067)](https://camo.githubusercontent.com/2dba8c839eeec5f61a582a89ac442e8181d4e60df716f781ad2231ed5beee5b9/68747470733a2f2f7778312e73696e61696d672e636e2f6d773639302f36623934613265356c7931676c30777a74657670786a323079693161756a77622e6a7067)

手动更新离线包
-------

[](#手动更新离线包)

1，纯真IP库（需要安装 EXE ，解压获得离线包）

2，IPV6（目前已经不再提供离线下载包）

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity58

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 98.3% 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 ~163 days

Recently: every ~138 days

Total

20

Last Release

899d ago

Major Versions

v1.0.3 → v2.0.12017-09-11

v2.0.9 → 3.0.02021-04-09

v2.1.0 → 3.0.12022-05-26

2.x-dev → 3.x-dev2023-12-01

PHP version history (3 changes)v1.0.0PHP &gt;=5.3.3

v2.0.6PHP ~5.4|~7.0

v2.1.0PHP \*

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a4e26a47fd5873f6f9adff3849459a3f268cbc80f40d888827eddcb9f037d29?d=identicon)[itbdw](/maintainers/itbdw)

---

Top Contributors

[![itbdw](https://avatars.githubusercontent.com/u/1267057?v=4)](https://github.com/itbdw "itbdw (59 commits)")[![whirlwind110](https://avatars.githubusercontent.com/u/12848936?v=4)](https://github.com/whirlwind110 "whirlwind110 (1 commits)")

---

Tags

dbip-addressip-databaseipv4ipv6phpphp-ipqqwrydatabaseIPlocationChineseChina

### Embed Badge

![Health badge](/badges/itbdw-ip-database/health.svg)

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

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[doctrine/doctrine-bundle

Symfony DoctrineBundle

4.8k241.3M3.3k](/packages/doctrine-doctrine-bundle)[doctrine/migrations

PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.

4.8k204.8M440](/packages/doctrine-migrations)[doctrine/data-fixtures

Data Fixtures for all Doctrine Object Managers

2.8k136.1M516](/packages/doctrine-data-fixtures)[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k46.2M405](/packages/robmorgan-phinx)

PHPackages © 2026

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