PHPackages                             hightman/ipconv - 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. hightman/ipconv

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

hightman/ipconv
===============

IPv4 address converter and query, such as country, city, ISP

1.0.0(7y ago)919MITPHPPHP &gt;=5.4.0

Since Nov 18Pushed 6y ago1 watchersCompare

[ Source](https://github.com/hightman/ipconv)[ Packagist](https://packagist.org/packages/hightman/ipconv)[ Docs](https://github.com/hightman/ipconv/)[ RSS](/packages/hightman-ipconv/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

简易IP地址信息转换查询
============

[](#简易ip地址信息转换查询)

这是一个用 [PHP](http://php.net) 编写的 IPv4 地址信息转换查询库。 常用作于快速将 IP 地址转换为所在省市等地理位置、网络服务提供商等信息， 以便针对用户提供本地化的定制应用。

同时还包含一份基于纯真网络IP库的信息整理国内省市信息查询数据，可将 IPv4 地址转换为国内的省市及网络商信息，以及海外的国家名称。

- 纯 PHP 编写无其它依赖模块
- 采用二分查找，查询性能高
- 提供数据生成工具，方便定制数据
- 免费开源，基于 MIT license

Requirements
------------

[](#requirements)

PHP &gt;= 5.4.0

Install
-------

[](#install)

### Install from an Archive File

[](#install-from-an-archive-file)

Extract the archive file downloaded from [ipconv-master.zip](https://github.com/hightman/ipconv/archive/master.zip)to your project. And then add the library file into your program:

```
require '/path/to/Query.php';
```

### Install via Composer

[](#install-via-composer)

If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).

You can then install this library using the following command:

```
php composer.phar require "hightman/ipconv:*"

```

Usage
-----

[](#usage)

### 查询

[](#查询)

使用非常简单，只需在实例化 `\hightman\ipconv\Query` 类后，调用 `Query()` 方法即可。 示范代码如下：

```
use hightman\ipconv\Query;

// 1. 实例化查询对象
// 默认会加载自带的 ipconv.dat，提供国内城市信息检索
// 如需指定自定义数据文件，请调用 open 方法
$ipc = new Query();
//$ipc->open('/path/to/file.dat');

// 2. 执行查询，支持 IPv4 地址、域名
// 如果有数据匹配，返回结果为两段信息描述组成的数组
// 如果没有匹配的数据返回 false ，如果出错则抛出 \InvalidArgumentException 异常
try {
     var_dump($ipc->query('210.32.1.1'));
     var_dump($ipc->query('haiman.io'));
} catch (\InvalidArgumentException $e) {
}

// 3. 打印版本信息
echo $ipc->version();
```

### Demo

[](#demo)

支持命令行、网页形式访问内置的 `demo.php`，无需多说，跑起来就懂。

### 定制创建数据

[](#定制创建数据)

你可以通过附带的 `build-data.php` 根据自己的需求打造数据，实现通过 IP 地址快速查询任意信息。 用法参考如下：

```
php build-data.php  [output file]

```

- 必填参数 nput file: IP 信息数据文本文件，格式详见后述
- 选填参数 output file: 输出文件存储位置，默认同输入路径并将后缀改为 .dat

### 用于输入的数据格式说明

[](#用于输入的数据格式说明)

格式为纯文本文件，每行为一条记录，每条记录由 4 个字段组成，字段时间用任意空格或制表符分隔， 空格数量任意均可，纯真 IP 数据导出后存为 UTF-8 即可直接使用。因此，仅最后那个字段内容可以包含空格。

对数据无排序要求，即使地址范围重叠、断档亦无所谓，转换程序会自动进行修正，这对于编写信息文件将十分方便。 四个字段的含义如下：

```

```

如果起始IP信息表述为 CIDR 的形式，则忽略结束IP字段，每个信息描述字段最多可达 255 字节。用法举例如下：

```
218.10.6.45     218.10.6.57     黑龙江省齐齐哈尔市 网通
218.10.6.58     218.10.6.58     黑龙江省齐齐哈尔市 梅里斯区雅尔塞镇欣欣网吧
218.10.6.75     218.10.6.75     黑龙江省齐齐哈尔市拜泉县 超人网吧
218.10.6.59     218.10.6.74     黑龙江省齐齐哈尔市 网通

210.32.0.0/16                   浙江省杭州市  浙江大学

```

### About dev-data

[](#about-dev-data)

...

Contact me
----------

[](#contact-me)

If you have any questions, please report on github [issues](https://github.com/hightman/iconv/issues)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Unknown

Total

1

Last Release

2782d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/720b188c6d958d43fbf848b3211a7a8419cc4ef9e116913763835782d4dd134d?d=identicon)[hightman](/maintainers/hightman)

---

Top Contributors

[![hightman](https://avatars.githubusercontent.com/u/812381?v=4)](https://github.com/hightman "hightman (2 commits)")

---

Tags

phpgeolocationIPcountrycity

### Embed Badge

![Health badge](/badges/hightman-ipconv/health.svg)

```
[![Health](https://phpackages.com/badges/hightman-ipconv/health.svg)](https://phpackages.com/packages/hightman-ipconv)
```

###  Alternatives

[zoujingli/ip2region

ip2region v3.0 for PHP - 企业级 IP 地理位置查询库，支持 IPv4 和 IPv6，多种缓存策略，零依赖，开箱即用

1.4k462.5k65](/packages/zoujingli-ip2region)[sun/country

Sun Country is the package that helps you to get the country name &amp; dialing code by the country ISO 3166-1 Alpha-2 code.

1016.8k](/packages/sun-country)[damianociarla/select-city-form-field-bundle

This Bundle provides a new form field that renders three select 'Country, Region, City' for Symfony2

101.9k](/packages/damianociarla-select-city-form-field-bundle)

PHPackages © 2026

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