Skip to content

Commit 2f91a8a

Browse files
committed
update database
1 parent 8e07f55 commit 2f91a8a

4 files changed

Lines changed: 36 additions & 21 deletions

File tree

README.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1-
# ip-database
1+
# 免费IP数据库 (纯真IP库,已经格式为国家、省、市、县、运营商)
22

3-
## PHP IP 地址工具
4-
只需要 php 环境即可本地解析 ip,不需要网络请求,非常快
3+
此工具基于纯真 IP 库,并且把非结构化的数据结构化。
54

6-
## Usage
5+
一旦识别了 IP,都可以显示国家。国内 ip 都能识别出省,基本可以识别出市、运营商,有部分能识别出县,以及公司小区学校网吧等信息。
6+
7+
## 环境要求
8+
9+
只需要 php 环境即可本地解析 ip。
10+
不需要网络请求。
11+
第一次查询即读入内存,以后直接从内存读取,效率非常高。
12+
13+
## 数据库文件更新日期
14+
15+
2017年9月12日
16+
17+
## 使用说明
718

819
```
920
composer require 'itbdw/ip-database'
1021
```
1122

1223
```php
24+
25+
//根据实际情况,基本上用框架(如 Laravel)的话不需要手动引入
26+
//require 'vender/autoload.php';
27+
1328
use itbdw\Ip\IpLocation;
1429

1530
$hostname = 'itbdw.com';
@@ -20,39 +35,39 @@ echo $hostname . "\n";
2035
echo json_encode(IpLocation::getLocation($ip), JSON_UNESCAPED_UNICODE) . "\n";
2136
```
2237

23-
## 数据库文件更新
24-
25-
由于我目前没有 Windows 电脑,所以IP文件已经很久没有更新了。
26-
27-
http://www.cz88.net/fox/ipdat.shtml
28-
下载数据库程序(Windows 环境),执行完毕后,将 QQWry.dat 文件重命名为 qqwry.dat 放到对应目录即可
29-
30-
## test case, so cool!
38+
## 测试合法性
3139

3240
```
3341
➜ php tests/ip.php
3442
qq.com
3543
```
36-
case ok
44+
正确数据
3745
```json
3846
{
3947
"ip": "163.177.65.160",
4048
"country": "中国",
41-
"province": "广东省",
49+
"province": "广东",
4250
"city": "深圳市",
4351
"county": "",
4452
"isp": "联通",
4553
"area": "中国广东省深圳市腾讯计算机系统联通节点"
4654
}
4755
```
4856

49-
case error
57+
异常情况
5058
```json
5159
{
5260
"error": "ip invalid"
5361
}
5462
```
5563

64+
## 自己手动更新数据库
65+
66+
http://www.cz88.net/fox/ipdat.shtml
67+
下载数据库程序(Windows 环境),执行完毕后,把 qqwry.dat 复制到 src 目录,覆盖掉原文件即可
68+
69+
70+
5671
##Thanks
5772
+ 1, qqary.dat database provider http://www.cz88.net/fox/ipdat.shtml
5873
+ 2, class original provider 马秉尧
@@ -65,6 +80,7 @@ case error
6580
2017-09-12 赵彬言 1,缩减返回数据,去掉字段 remark smallarea baginip endip
6681
2,将调用改为单例模式,保证只读取一次文件
6782
3,修复 bug,直接将返回 gbk 编码内容转为 utf-8,移除编码隐患
83+
4,去掉了"省"标志,变成了如 中国 浙江 杭州市 这样的数据
6884
6985
2017-09-04 赵彬言 1,更新 composer 相对路径,bug fix
7086

src/IpLocation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class IpLocation
5858
'移动',
5959
'铁通',
6060
'电信',
61+
'长城',
62+
'聚友',
6163
];
6264

6365
/**

src/qqwry.dat

29.9 KB
Binary file not shown.

tests/ip.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* @author Zhao Binyan <zhao.binyan@immomo.com>
3+
* @author Zhao Binyan <itbudaoweng@gmail.com>
44
* @since 2015-06-11
55
*/
66

@@ -10,19 +10,16 @@
1010
use itbdw\Ip\IpLocation;
1111

1212
$hostnames = [
13-
'qq.com',
1413
'baidu.com',
15-
'360.com',
1614
'immomo.com',
1715
'github.com',
18-
'sina.com.cn',
19-
'yungbo.com',
2016
'aliyun.com',
2117
'google.com',
22-
18+
'weibo.com'
2319
];
2420
shuffle($hostnames);
2521
$hostname = array_pop($hostnames);
22+
2623
$ip = gethostbyname($hostname);
2724

2825
echo $hostname . "\n";

0 commit comments

Comments
 (0)