Giter Site home page Giter Site logo

ip-database's Introduction

说明

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

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

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

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

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

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

使用说明

当前版本为3.x(ipv4+ipv6),如需要2.x请访问 https://github.com/itbdw/ip-database/tree/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":"移动"}

提高下载速度

建议腾讯云加速 https://mirrors.cloud.tencent.com/help/composer.html

原因 #42

赞助喝口水

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

手动更新离线包

1,纯真IP库(需要安装 EXE ,解压获得离线包) https://www.cz88.net/help?id=free

2,IPV6(目前已经不再提供离线下载包) https://ip.zxinc.org/ipquery/

ip-database's People

Contributors

itbdw avatar whirlwind110 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ip-database's Issues

An exception occurrs when querying few specfic IP

Hi,Master
Thx for your project, it really helps.
Rectently, using the tool, I found an issue attached the related logs as follow.
An exception occurrs when encountering the specfic IP 111.12.25.35 as input.
FYI, after I tested some cases, I found the exception occurrs whenever IP involes IP subnet 111.12.. .

### normal test case result is fine
php D:\SRC_Code\PHP_Project\ip-database-2.0.9\tests\ip.php -i 36.147.19.241
{"ip":"36.147.19.241","country":"**","province":"北京","city":"","county":"","isp":"移动","area":"**北京移动"}

### err log ###
php D:\SRC_Code\PHP_Project\ip-database-2.0.9\tests\ip.php -i 111.12.25.35
Fatal error: Uncaught Error: Call to undefined function itbdw\Ip\mb_stripos() in D:\SRC_Code\PHP_Project\ip-database-2.0.9\src\IpLocation.php:276
Stack trace:
#0 D:\SRC_Code\PHP_Project\ip-database-2.0.9\src\IpLocation.php(171): itbdw\Ip\IpLocation->getAddr('111.12.25.35')
#1 D:\SRC_Code\PHP_Project\ip-database-2.0.9\tests\ip.php(43): itbdw\Ip\IpLocation::getLocation('111.12.25.35')
#2 {main}
thrown in D:\SRC_Code\PHP_Project\ip-database-2.0.9\src\IpLocation.php on line 276

image

composer require itbdw/ip-database ^3.0.1,不能满足最小稳定版本

❯ composer require itbdw/ip-database ^3.0.1 -W --no-cache
./composer.json has been updated
Running composer update itbdw/ip-database --with-all-dependencies
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires itbdw/ip-database ^3.0.1, found itbdw/ip-database[3.x-dev] but it does not match your minimum-stability.


Installation failed, reverting ./composer.json and ./composer.lock to their original content.

我的 PHP 是 7.4,composer.json 中 minimum-stabilitystable
如果 minimum-stabilitydev 就不会出现这个问题。但这样是不够安全的。

直接使用file_get_contents下载 会出错。 需要添加 header 信息。

$copywrite = curls_get("http://update.cz88.net/ip/copywrite.rar");
$qqwry = curls_get("http://update.cz88.net/ip/qqwry.rar");

function curls_get($url)
{
$header = ["User-Agent:Mozilla/3.0 (compatible; Indy Library)","Accept:text/html, /"];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 600,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => $header,
CURLOPT_URL => $url,
));
$res = curl_exec($curl);
curl_close($curl);
return $res;
}

IPv6 结果存在\t制表符

{"ip":"2400:3200:baba::1","country":"**","province":"**\t浙江","city":"\t杭州市","county":"","area":"****\t浙江\t杭州市 阿里云计算有限公司","isp":""}

某些IP的市这个值是乱码

比如:120.193.188.229

看了下,貌似是ltrim引起的问题,ltrim,rtrim啥的不支持中文的,建议使用mb_substr来进行切割

一个疑问,是这样的,我复制作者到创建的仓库,就出现一个问题

主要是我一直用国内:阿里云镜像,快啊。
但是无法安装作者你写的。。用原生repo.packagist.org慢啊。。
这是我自己复制到我仓库的:https://github.com/hulang/think-ip
目前出现一个问题,一直提示错误:
unpack(): Type V: not enough input, need 4, have 1
如果可以,作者你指点下啊。。最好能使用:阿里云镜像更新。。。我就不用复制仓库了。。
@itbdw

感谢提供源代码,我基于你的代码,移植了Ruby版的gem包

在移植时,我发现有些少数名族的城市名不好提取。比如“四川省凉山州西昌市”,“凉山州”是城市,“西昌市”是县。又如”内蒙古锡林郭勒盟“,”锡林郭勒盟“是城市。

要实现准确提取,我想可能需要**的城市库。要实现这个功能,需要花些时间整理省市区县的数据。不知你在业务应用中是否已经做个这个事了?能否共享出来?

附上我移植的Ruby Gem地址:https://github.com/xiaohui-zhangxh/ip_locator_cn

v3.x 可以支持 PHP8不

Problem 1
- Root composer.json requires itbdw/ip-database ^3.0 -> satisfiable by itbdw/ip-database[3.0.0].
- itbdw/ip-database 3.0.0 requires php ~5.4|~7.0 -> your php version (8.0.8) does not satisfy that requirement.

返回 无数据2020年1月15日IP数据

["ip"]=> string(14) "115.226.116.52" ["beginip"]=> string(13) "255.255.255.0" ["endip"]=> string(15) "255.255.255.255" ["country"]=> string(8) "纯真网络" ["area"]=> string(19) "2020年1月15日IP数据"

需要更新ip库了

ip 116.139.189.164,解析出来是北京,实际是辽宁的
版本"itbdw/ip-database": "^3.0",

need php8+ support

测试 v3.0版本 可以在php8.0环境下运行 , 但Composer require中php版本并未添加php8+

代码重构以及支持 IPV6

新功能

  • 新功能,使用 3.x 分支
  • 不向后兼容。代码结构重新设计。
  • 尝试支持ipdb
  • 支持IPV6
  • 采用民政部公布的区域码

1,时间太长,代码结构不够好。需要重构代码,将读取IP和格式化分开,以支持更多数据源。
2,�尝试联系 http://ip.zxinc.org/ipquery/ 站长,可否使用 ipv6 库

找不到 QQwry 类

Fatal error: Uncaught Error: Class 'itbdw\Ip\IpParser\QQwry' not found in /ip-database/src/IpLocation.php on line 47

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.