Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge from remote #5

Merged
merged 135 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
4feeb03
Merge pull request #68 from RocherKong/master
lionsoul2014 Jul 31, 2018
f2f80fc
Update to the latest data of version 2018/07/26
lionsoul2014 Jul 31, 2018
f82d3be
Fix the bug for btree header fetch
lionsoul2014 Jul 31, 2018
b7e9755
java binding version 1.7 with btree search bug fixed
lionsoul2014 Jul 31, 2018
487129d
[Feature] Add 'memorySearch' and 'memorySearchSync' for Nodejs
Jul 31, 2018
f3ae83a
add use stream method
stulzq Aug 19, 2018
f482591
Merge pull request #69 from Maledong/master
lionsoul2014 Aug 25, 2018
4556afd
[nodejs] publish package on npm
Aug 30, 2018
9623e34
Merge pull request #72 from stulzq/master
lionsoul2014 Sep 1, 2018
1312bdb
Update the maven version to 1.7
lionsoul2014 Sep 5, 2018
7322733
Merge branch 'master' of https://github.com/lionsoul2014/ip2region
lionsoul2014 Sep 5, 2018
d82447c
Merge pull request #76 from a631807682/master
lionsoul2014 Oct 2, 2018
cd84dff
Add some notices
lionsoul2014 Oct 2, 2018
679f30a
Add DbSearcher(dbConfig, dbBinStr) construct method specified by Wend…
lionsoul2014 Oct 2, 2018
1f04c55
Update the maven version number to 1.7.2
lionsoul2014 Oct 2, 2018
04f093d
lua binding basic framework with memory search completed(tested)
lionsoul2014 Oct 2, 2018
5f073d8
lua binding forward with binarySearch and btreeSearch interface imple…
lionsoul2014 Oct 3, 2018
86ad805
Lua binding completed(tested)
lionsoul2014 Oct 3, 2018
e6104dc
Update README for lua binding
lionsoul2014 Oct 3, 2018
5f871ba
Update the Lua binding
lionsoul2014 Oct 3, 2018
a2d2509
Update the lua interface and add setDbFile interface
lionsoul2014 Oct 4, 2018
593aba6
重构python客户端,提升查询性能,兼容python2.x,3.x
Oct 4, 2018
8e278d9
Merge pull request #81 from KomaBeyond/master
lionsoul2014 Oct 5, 2018
e9a08e2
Optimize the benchmark script
lionsoul2014 Oct 5, 2018
7032830
Optimize the lua module by add the __index and the __tostring meta-me…
lionsoul2014 Oct 5, 2018
7bd8129
lua_c binding basic framework(Not tested yet...)
lionsoul2014 Oct 5, 2018
e26ed44
lua_c module forward with basic framework finished(tested)
lionsoul2014 Oct 5, 2018
93689e0
lua binding module interface stdlize with new and ip2long method acce…
lionsoul2014 Oct 5, 2018
f9e9dd5
lua ip2region c module forward with release version published
lionsoul2014 Oct 6, 2018
03fd40b
Add README doc for lua_c module
lionsoul2014 Oct 6, 2018
bd6dc7b
Update the README doc for lua_c module
lionsoul2014 Oct 6, 2018
86104eb
Optimize the ip2long function with trim logic applied
lionsoul2014 Oct 7, 2018
253dc12
Add automatically lib dir make
lionsoul2014 Oct 7, 2018
9c37b5b
Optimize the lua_c module
lionsoul2014 Oct 10, 2018
281237c
Update README.md
heweizhen0822 Oct 18, 2018
06e8aa2
Update main.go
heweizhen0822 Oct 18, 2018
e4d3772
Merge pull request #85 from heweizhen0822/patch-2
lionsoul2014 Oct 18, 2018
a6968d9
Merge pull request #86 from heweizhen0822/patch-1
lionsoul2014 Oct 18, 2018
ab1c331
Update the merge to version 1.2.1
lionsoul2014 Nov 3, 2018
74b2909
ip source text and binary data upgrade to version 2018/12/31
lionsoul2014 Dec 31, 2018
41b9c2d
Track the CHANGES for version 1.8.0
lionsoul2014 Dec 31, 2018
a7dfe94
Update the CHANGES for maven address update and lua comments
lionsoul2014 Dec 31, 2018
4dabf63
Upgrade the lodash base version to 4.17.11
lionsoul2014 Feb 12, 2019
9d23bc5
Upgrade the ip source data and db data to the latest version 2019/05/02
lionsoul2014 May 2, 2019
abf2292
Add the java implementation for ip2region.db maker
lionsoul2014 May 2, 2019
5767b1e
Optimize the maker doc
lionsoul2014 May 2, 2019
00f18bf
Add source data platform or API url
lionsoul2014 May 5, 2019
354a6c9
Optimize the source data list display
lionsoul2014 May 5, 2019
eebf8c6
Optimize the source data list display
lionsoul2014 May 5, 2019
e670bc1
Add source data platform or API url
lionsoul2014 May 5, 2019
4a59fa6
Add source data platform or API url
lionsoul2014 May 5, 2019
151de1a
Optimize the data source list display
lionsoul2014 May 5, 2019
a8f77a9
fix the bug of raf=null in the close interface of DbSearcher
lionsoul2014 Jul 7, 2019
a2e2262
Merge branch 'master' of https://gitee.com/lionsoul/ip2region
lionsoul2014 Jul 7, 2019
bb3740f
Upgrade some the dependencies version to the one followed by the gith…
lionsoul2014 Jul 7, 2019
a49b7de
Upgrade some the dependencies version to the one followed by the gith…
lionsoul2014 Jul 7, 2019
f483af3
Security Alerts fixing
lionsoul2014 Jul 21, 2019
d071daf
add support for nginx
Cherisher Aug 22, 2019
f11b809
Merge pull request #125 from Cherisher/master
lionsoul2014 Aug 22, 2019
5c1394a
add nginx module support
lionsoul2014 Aug 22, 2019
41ea94f
Upgrade mixin-deep for version 1.3.2 and set-value to version 2.0.1
lionsoul2014 Sep 7, 2019
589abb5
Update the README
lionsoul2014 Oct 27, 2019
9ef5c4a
Upgrade the data to the version of 2019/10/27
lionsoul2014 Oct 27, 2019
2baa088
Upgrade the DOC for upgrade desc
lionsoul2014 Oct 28, 2019
e57d010
Update the data to the latest version
lionsoul2014 Nov 23, 2019
79a1956
Merge pull request #138 from RocherKong/master
lionsoul2014 Dec 11, 2019
238f119
Bump handlebars from 4.1.2 to 4.5.3 in /binding/nodejs
dependabot[bot] Dec 27, 2019
0a2d8fa
Merge pull request #140 from lionsoul2014/dependabot/npm_and_yarn/bin…
lionsoul2014 Dec 28, 2019
2e4d5d5
update nodejs client and use node-ip2region for npm package name
dongyado Feb 20, 2020
25f82ba
update readme add tested node version
dongyado Feb 20, 2020
b75d215
Optimize the README DOC
lionsoul2014 Feb 21, 2020
6c31b18
Merge branch 'master' of https://gitee.com/lionsoul/ip2region
lionsoul2014 Feb 21, 2020
b092eb1
Optimize the DOC
lionsoul2014 Feb 21, 2020
33798b5
Optimize the README DOC
lionsoul2014 Feb 21, 2020
710f806
Optimize the installation DOC
lionsoul2014 Feb 21, 2020
6f3d0d5
Optimize the installation DOC and rename the php ext binding name
lionsoul2014 Feb 21, 2020
f09285a
Update the link for the php ext
lionsoul2014 Feb 21, 2020
e701781
update db structure intro file link
dongyado Mar 16, 2020
28f818e
fix memory leak and symbol duplicate
phpstatic Mar 22, 2020
44059a4
fix php5 symbol duplicate
phpstatic Mar 22, 2020
9715647
Merge pull request #147 from phpstatic/master
lionsoul2014 Mar 22, 2020
e7a666b
Upgrade the kind-of to version 6.0.3
lionsoul2014 Apr 2, 2020
d077ab1
Merge branch 'master' of https://gitee.com/lionsoul/ip2region
lionsoul2014 Apr 2, 2020
07287ea
Upgrade the minimist to 1.2.2
lionsoul2014 Apr 2, 2020
c6b3e79
upgrade the acorn to version 5.7.4
lionsoul2014 Apr 2, 2020
a9571d4
add DataBlock
Jun 10, 2020
bf07725
add HeaderBlock.cs
Jun 10, 2020
e13f9b4
add DbSearcher
Jun 10, 2020
1d02185
clean code
Jun 10, 2020
399f4a5
rename to Java style.
Soar360 Jun 11, 2020
06685a3
add sln file
Soar360 Jun 11, 2020
cfa2918
add DbMaker.cs
Soar360 Jun 11, 2020
56a9fe8
Util.cs -> ip2long
Soar360 Jun 11, 2020
e8439a6
Upgrade the source and binary data to the latest 2020/06/10 version
lionsoul2014 Jun 13, 2020
d62ede3
Upgrade the minimist version inspired by the github alerts
lionsoul2014 Jun 18, 2020
d2d3a5e
Merge branch 'master' of https://gitee.com/lionsoul/ip2region
lionsoul2014 Jun 18, 2020
9101c21
add CSharp Macker
Soar360 Jul 9, 2020
667cdc8
Bump lodash from 4.17.13 to 4.17.19 in /binding/nodejs
dependabot[bot] Jul 16, 2020
083768b
Merge pull request #160 from lionsoul2014/dependabot/npm_and_yarn/bin…
lionsoul2014 Jul 20, 2020
40bd5a7
Fix multi instance bugs, use instance variable instead of class varia…
Wuxiaodonggit Sep 2, 2020
9f01108
Merge pull request #163 from Wuxiaodonggit/python_fixbug
lionsoul2014 Sep 3, 2020
11da0e9
Create readme.md
zzl88824 Sep 18, 2020
9f01d66
Add files via upload
zzl88824 Sep 18, 2020
7b30c30
Update readme.md
zzl88824 Sep 18, 2020
50e931c
Update readme.md
zzl88824 Sep 18, 2020
db3f5f3
Add files via upload
zzl88824 Sep 18, 2020
f36b458
Merge pull request #168 from zzl88824/master
lionsoul2014 Sep 18, 2020
f0be894
fix bug about stack corrupt for example ip address is spceial "172.1…
liyang1009 Oct 6, 2020
bf8f6a7
Merge pull request #159 from coderbusy/master
lionsoul2014 Oct 10, 2020
e8c9b39
Merge pull request #171 from liyang1009/master
lionsoul2014 Oct 11, 2020
646873b
Bump junit from 3.8.1 to 4.13.1 in /binding/java
dependabot[bot] Oct 12, 2020
813337d
Merge pull request #174 from lionsoul2014/dependabot/maven/binding/ja…
lionsoul2014 Oct 13, 2020
6b6480e
Upgrade the origin ip and binary data to the latest 2020/10/31 releas…
Oct 31, 2020
f3f3c9e
Merge branch 'master' of https://github.com/lionsoul2014/ip2region
Oct 31, 2020
e97c34e
新版 C# 数据库生成器
Soar360 Dec 3, 2020
74947ca
!7 新版 C# 数据库生成器
lionsoul2014 Dec 12, 2020
e923b0d
Upgrade the origin and binary db data to the latest 2020/03/06 version
Mar 8, 2021
57afca2
Merge branch 'master' of https://gitee.com/lionsoul/ip2region
Mar 8, 2021
e42d45b
Upgrade the origin and binary db data to the latest 2020/03/06 version
Mar 8, 2021
b7a7887
Bump y18n from 3.2.1 to 3.2.2 in /binding/nodejs
dependabot[bot] Mar 30, 2021
57da31c
Bump handlebars from 4.5.3 to 4.7.7 in /binding/nodejs
dependabot[bot] May 6, 2021
64e2830
Bump lodash from 4.17.19 to 4.17.21 in /binding/nodejs
dependabot[bot] May 7, 2021
4d43d8b
Merge pull request #194 from lionsoul2014/dependabot/npm_and_yarn/bin…
lionsoul2014 May 8, 2021
dc94fe9
Bump hosted-git-info from 2.4.2 to 2.8.9 in /binding/nodejs
dependabot[bot] May 8, 2021
deb4980
Merge pull request #195 from lionsoul2014/dependabot/npm_and_yarn/bin…
lionsoul2014 May 8, 2021
5e6335d
Merge pull request #187 from lionsoul2014/dependabot/npm_and_yarn/bin…
lionsoul2014 May 8, 2021
f92bcf3
Merge pull request #193 from lionsoul2014/dependabot/npm_and_yarn/bin…
lionsoul2014 May 8, 2021
e0fed1b
Bump path-parse from 1.0.5 to 1.0.7 in /binding/nodejs
dependabot[bot] Aug 10, 2021
4de96c8
Bump tmpl from 1.0.4 to 1.0.5 in /binding/nodejs
dependabot[bot] Sep 20, 2021
b304cd0
Merge pull request #206 from lionsoul2014/dependabot/npm_and_yarn/bin…
lionsoul2014 Oct 24, 2021
4e106af
Merge pull request #203 from lionsoul2014/dependabot/npm_and_yarn/bin…
lionsoul2014 Oct 24, 2021
351b914
Fix the region name and re-generate the binary file
lionsoul2014 Oct 25, 2021
5c947be
Merge branch 'master' of https://gitee.com/lionsoul/ip2region
lionsoul2014 Oct 25, 2021
ee5519b
Bump async from 2.3.0 to 2.6.4 in /binding/nodejs
dependabot[bot] Apr 28, 2022
75bac23
Merge pull request #220 from lionsoul2014/dependabot/npm_and_yarn/bin…
lionsoul2014 Apr 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*.o
*.pyc
*~
*.log
*.la
*.so
META-INF/

# Binary Files #
Expand Down Expand Up @@ -37,3 +40,7 @@ target
/binding/c#/**/packages
/binding/c#/**/bin
/binding/c#/**/obj

# Nodejs
/binding/nodejs/tests/unitTests/__snapshots__
/binding/nodejs/coverage
23 changes: 23 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
### 1.8
1. 数据升级至2018/12/31的版本,国外的也增加了大量的城市数据。
2. Java的binding的Searcher类增加了如下的接口和实现:
```java
DbSearcher(DbConfig dbConfig, string dbBinStr);
```

maven坐标:
```xml
<dependency>
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
<version>1.7.2</version>
</dependency>
```

3. Javascript的pacakge上传到了npm。
4. 增加纯lua实现的lua binding (lua 5.2版本依赖bit模块,对5.3的支持将使用lua自带的bit操作)。
5. 增加C实现的lua_c binding (和c的性能等同,建议使用)。
6. 优化部分binding的demo运行和使用文档。
7. 修复python binding的benchmark的部分错误。


### 1.2.4
1, 花了近两周的时间重写了数据的升级算法,再次提高准确率,升级过程如下(此处应该有掌声):

Expand Down
179 changes: 119 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,81 @@
ip2region - 最自由的ip地址查询库,ip到地区的映射库,提供Binary,B树和纯内存三种查询算法,妈妈再也不用担心我的ip地址定位。
# Ip2region是什么?

### 1. 99.9%准确率,定时更新:
ip2region - 准确率99.9%的离线IP地址定位库,0.0x毫秒级查询,ip2region.db数据库只有数MB,提供了java,php,c,python,nodejs,golang,c#等查询绑定和Binary,B树,内存三种查询算法。

数据聚合了一些知名ip到地名查询提供商的数据,这些是他们官方的的准确率,经测试着实比纯真啥的准确多了。<br />
每次聚合一下数据需要1-2天,会不定时更新。

### 2. 标准化的数据格式:

每条ip数据段都固定了格式:_城市Id|国家|区域|省份|城市|ISP_

只有中国的数据精确到了城市,其他国家只能定位到国家,后前的选项全部是0,已经包含了全部你能查到的大大小小的国家。
(请忽略前面的城市Id,个人项目需求)
# Ip2region特性

### 3. 体积小:
### 99.9%准确率

生成的数据库文件ip2region.db只有1.5M(1.2版本前是3.5M)
数据聚合了一些知名ip到地名查询提供商的数据,这些是他们官方的的准确率,经测试着实比经典的纯真IP定位准确一些。<br />
ip2region的数据聚合自以下服务商的开放API或者数据(升级程序每秒请求次数2到4次): <br />
01, &gt;80%, 淘宝IP地址库, [http://ip.taobao.com/](http://ip.taobao.com/) <br />
02, ≈10%, GeoIP, [https://geoip.com/](https://geoip.com/) <br />
03, ≈2%, 纯真IP库, [http://www.cz88.net/](http://www.cz88.net/) <br />
<b>备注:</b>如果上述开放API或者数据都不给开放数据时ip2region将停止数据的更新服务。

### 4. 多查询客户端的支持,0.0x毫秒级别的查询

已经集成的客户端有:java, C#, php, c, python,nodejs,php扩展(支持linux, php5, php7版本已支持),golang。
### 标准化的数据格式

提供了两种查询算法,响应时间如下:
客户端/binary算法/b-tree算法/Memory算法:
c#/0.x毫秒/0.x毫秒/0.x毫秒
java/0.x毫秒/0.x毫秒/0.1x毫秒 (使用RandomAccessFile)
php/0.x毫秒/0.1x毫秒/0.1x毫秒
c/0.0x毫秒/0.0x毫秒/0.00x毫秒(b-tree算法基本稳定在0.02x毫秒级别)
python/0.x毫秒/0.1x毫秒/未知

任何客户端b-tree都比binary算法快,当然Memory算法固然是最快的!

maven仓库地址:
```xml
<dependency>
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
<version>1.4</version>
</dependency>
每条ip数据段都固定了格式:
```
nuget安装命令
```shell
Install-Package IP2Region
_城市Id|国家|区域|省份|城市|ISP_
```

### 5. 测试程序:
C# 和 Node.js,请具体参考文件夹中README.md 说明。
只有中国的数据精确到了城市,其他国家有部分数据只能定位到国家,后前的选项全部是0,已经包含了全部你能查到的大大小小的国家(请忽略前面的城市Id,个人项目需求)。

java:
```shell
cd binding/java
ant all
java -jar ip2region-{version}.jar ./data/ip2region.db
```

php:
```shell
php binding/php/testSearcher.php ./data/ip2region.db
```
### 体积小

包含了全部的IP,生成的数据库文件ip2region.db只有几MB,最小的版本只有1.5MB,随着数据的详细度增加数据库的大小也慢慢增大,目前还没超过8MB。


### 查询速度快

全部的查询客户端单次查询都在0.x毫秒级别,内置了三种查询算法

c:
1. memory算法:整个数据库全部载入内存,单次查询都在0.1x毫秒内,C语言的客户端单次查询在0.00x毫秒级别。
2. binary算法:基于二分查找,基于ip2region.db文件,不需要载入内存,单次查询在0.x毫秒级别。
3. b-tree算法:基于btree算法,基于ip2region.db文件,不需要载入内存,单词查询在0.x毫秒级别,比binary算法更快。

任何客户端b-tree都比binary算法快,当然memory算法固然是最快的!


### 多查询客户端的支持

已经集成的客户端有:java、C#、php、c、python、nodejs、php扩展(php5和php7)、golang、rust、lua、lua_c, nginx。

binding | 描述 | 开发状态 | binary查询耗时 | b-tree查询耗时 | memory查询耗时
:-: | :-: | :-: | :-: | :-: | :-:
[c](binding/c) | ANSC c binding | 已完成 | 0.0x毫秒 | 0.0x毫秒 | 0.00x毫秒
[c#](binding/c#) | c# binding | 已完成 | 0.x毫秒 | 0.x毫秒 | 0.1x毫秒
[golang](binding/golang) | golang binding | 已完成 | 0.x毫秒 | 0.x毫秒 | 0.1x毫秒
[java](binding/java) | java binding | 已完成 | 0.x毫秒 | 0.x毫秒 | 0.1x毫秒
[lua](binding/lua) | lua实现的binding | 已完成 | 0.x毫秒 | 0.x毫秒 | 0.x毫秒
[lua_c](binding/lua_c) | lua的c扩展 | 已完成 | 0.0x毫秒 | 0.0x毫秒 | 0.00x毫秒
[nginx](binding/nginx) | nginx的c扩展 | 已完成 | 0.0x毫秒 | 0.0x毫秒 | 0.00x毫秒
[nodejs](binding/nodejs) | nodejs | 已完成 | 0.x毫秒 | 0.x毫秒 | 0.1x毫秒
[php](binding/php) | php实现的binding | 已完成 | 0.x毫秒 | 0.1x毫秒 | 0.1x毫秒
[php5_ext](binding/php5_ext) | php5的c扩展 | 已完成 | 0.0x毫秒 | 0.0x毫秒 | 0.00x毫秒
[php7_ext](binding/php7_ext) | php7的c扩展 | 已完成 | 0.0毫秒 | 0.0x毫秒 | 0.00x毫秒
[python](binding/python) | python bindng | 已完成 | 0.x毫秒 | 0.x毫秒 | 0.x毫秒
[rust](binding/rust) | rust binding | 已完成 | 0.x毫秒 | 0.x毫秒 | 0.x毫秒




# ip2region快速测试

请参考每个binding下的README说明去运行cli测试程序,例如C语言的demo运行如下:
```shell
cd binding/c/
gcc -g -O2 testSearcher.c ip2region.c
./a.out ../../data/ip2region.db
```

python:
```shell
python binding/python/testSearcher.py ./data/ip2region.db
```

均会看到如下界面:
会看到如下cli界面:
```shell
initializing B-tree ...
+----------------------------------+
Expand All @@ -82,16 +87,60 @@ p2region>> 101.105.35.57
2163|中国|华南|广东省|深圳市|鹏博士 in 0.02295 millseconds
```

输入ip地址开始测试,第一次会稍微有点慢,在运行命令后面接入binary,memory来尝试其他算法,建议使用b-tree算法,速度和并发需求的可以使用memory算法。
输入IP地址开始测试,第一次会稍微有点慢,在运行命令后面接入binary,memory来尝试其他算法,建议使用b-tree算法,速度和并发需求的可以使用memory算法,具体集成请参考不同binding下的测试源码。




# ip2region安装

具体请参考每个binding下的README文档和测试demo,以下是一些可用的快捷安装方式:

### maven仓库地址
```xml
<dependency>
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
<version>1.7.2</version>
</dependency>
```

### nodejs
```
npm install node-ip2region --save
```

具体集成请参考不同客户端的测试源码。
### nuget安装
```shell
Install-Package IP2Region
```

### php composer
```shell
# 插件来自:https://github.com/zoujingli/ip2region
composer require zoujingli/ip2region
```



# ip2region 并发使用

1. 全部binding的各个search接口都<b>不是</b>线程安全的实现,不同线程可以通过创建不同的查询对象来使用,并发量很大的情况下,binary和b-tree算法可能会打开文件数过多的错误,请修改内核的最大允许打开文件数(fs.file-max=一个更高的值),或者使用持久化的memory算法。

2. memorySearch接口,在发布对象前进行一次预查询(本质上是把ip2region.db文件加载到内存),可以安全用于多线程环境。




# ip2region.db的生成

从1.8版本开始,ip2region开源了ip2region.db生成程序的java实现,提供了ant编译支持,编译后会得到以下提到的dbMaker-{version}.jar,对于需要研究生成程序的或者更改自定义生成配置的请参考${ip2region_root}/maker/java内的java源码。

### 6. 如何生成ip2region.db文件

从ip2region 1.2.2版本开始里面提交了一个dbMaker-{version}.jar的可以执行jar文件,用它来完成这个工作:
* 1, 确保你安装好了java环境(不玩Java的童鞋就自己谷歌找找拉,临时用一用,几分钟的事情)
* 2, cd到ip2region的根目录,然后运行如下命令:

1. 确保你安装好了java环境(不玩Java的童鞋就自己谷歌找找拉,临时用一用,几分钟的事情)
2. cd到${ip2region_root}/maker/java,然后运行如下命令:

```shell
java -jar dbMaker-{version}.jar -src 文本数据文件 -region 地域csv文件 [-dst 生成的ip2region.db文件的目录]
Expand All @@ -101,14 +150,24 @@ java -jar dbMaker-{version}.jar -src 文本数据文件 -region 地域csv文件
# ip2region.db文件的目录:是可选参数,没有指定的话会在当前目录生成一份./data/ip2region.db文件
```

* 3, 获取生成的ip2region.db文件覆盖原来的ip2region.db文件即可
* 4, 默认的ip2region.db文件生成命令:
3. 获取生成的ip2region.db文件覆盖原来的ip2region.db文件即可
4. 默认的ip2region.db文件生成命令:

```shell
cd ip2region项目根目录
cd ${ip2region_root}/java/
java -jar dbMaker-1.2.2.jar -src ./data/ip.merge.txt -region ./data/global_region.csv

# 会看到一大片的输出
```

* 5, 数据库文件的结构和原理请阅读 @冬芽 的blog:[“ip2region数据库文件的结构和原理”](http://dongyado.com/tool/2016/08/18/structure-of-ip2region-database-file/)



# 相关备注

### 声明
ip2region重点在于<b>研究IP数据的存储设计和各种语言的查询实现</b>,并没有原始IP数据的支撑,数据来源请参考上面的描述,升级数据需要很多IP的支撑并且会对原始平台造成一定量的请求压力,本项目不保证及时的数据更新,没有也不会有商用版本,你可以使用自定义的数据导入ip2region进行自定义查询的实现。

### 技术交流
1. 数据库文件的结构和原理请阅读 @冬芽 的blog:[“ip2region数据库文件的结构和原理”](https://github.com/dongyado/dongyado.github.io/blob/master/_posts/2016-08-18-structure-of-ip2region-database-file.md)
2. ip2region交流分享,微信:lionsoul2014(请备注ip2region),QQ:1187582057(很少关注)
Binary file added binding/LabVIEW/BinarySearch.vi
Binary file not shown.
Binary file added binding/LabVIEW/Close.vi
Binary file not shown.
Binary file added binding/LabVIEW/Example.vi
Binary file not shown.
Binary file added binding/LabVIEW/Get data.vi
Binary file not shown.
Binary file added binding/LabVIEW/Open.vi
Binary file not shown.
Binary file added binding/LabVIEW/ip2region.ctl
Binary file not shown.
Binary file added binding/LabVIEW/ip2region.db
Binary file not shown.
13 changes: 13 additions & 0 deletions binding/LabVIEW/ip2region.lvlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<Library LVVersion="19008000">
<Property Name="NI.Lib.Icon" Type="Bin">'1#!!!!!!!)!"1!&amp;!!!-!%!!!@````]!!!!"!!%!!!(]!!!*Q(C=\&gt;7R=2MR%!81N=?"5Q&lt;/07RB7W!,&lt;'&amp;&lt;9+K1,7Q,&lt;)%N&lt;!NMA3X)DW?-RJ(JQ"I\%%Z,(@`BA#==ZB3RN;]28_,V7@PWW`:R`&gt;HV*SU_WE@\N_XF[3:^^TX\+2YP)D7K6;G-RV3P)R`ZS%=_]J'XP/5N&lt;XH,7V\SEJ?]Z#5P?=J4HP+5JTTFWS%0?=B$DD1G(R/.1==!IT.+D)`B':\B'2Z@9XC':XC':XBUC?%:HO%:HO&amp;R7QT0]!T0]!S0I4&lt;*&lt;)?=:XA-(]X40-X40-VDSGC?"GC4N9(&lt;)"D2,L;4ZGG?ZH%;T&gt;-]T&gt;-]T?.S.%`T.%`T.)^&lt;NF8J4@-YZ$S'C?)JHO)JHO)R&gt;"20]220]230[;*YCK=ASI2F=)1I.Z5/Z5PR&amp;)^@54T&amp;5TT&amp;5TQO&lt;5_INJ6Z;"[(H#&gt;ZEC&gt;ZEC&gt;Z$"(*ETT*ETT*9^B)HO2*HO2*(F.&amp;]C20]C2)GN4UE1:,.[:/+5A?0^NOS?UJ^3&lt;*\9B9GT@7JISVW7*NIFC&lt;)^:$D`5Q9TWE7)M@;V&amp;D,6;M29DVR]6#R],%GC47T9_/=@&gt;Z5V&gt;V57&gt;V5E&gt;V5(OV?^T[FTP?\`?YX7ZRP6\D=LH%_8S/U_E5R_-R$I&gt;$\0@\W/VW&lt;[_"\Y[X&amp;],0^^+,]T_J&gt;`J@_B_]'_.T`$KO.@I"XC-_N!!!!!!</Property>
<Property Name="NI.Lib.SourceVersion" Type="Int">419463168</Property>
<Property Name="NI.Lib.Version" Type="Str">1.0.0.0</Property>
<Property Name="NI.LV.All.SourceOnly" Type="Bool">false</Property>
<Item Name="binarySearch.vi" Type="VI" URL="../binarySearch.vi"/>
<Item Name="Close.vi" Type="VI" URL="../Close.vi"/>
<Item Name="example.vi" Type="VI" URL="../example.vi"/>
<Item Name="Get data.vi" Type="VI" URL="../Get data.vi"/>
<Item Name="ip2region.ctl" Type="VI" URL="../ip2region.ctl"/>
<Item Name="Open.vi" Type="VI" URL="../Open.vi"/>
</Library>
7 changes: 7 additions & 0 deletions binding/LabVIEW/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ip2region的LabVIEW库<br>
使用方法:1. 将该目录下的所有文件复制到你的项目文件夹下;<br>
2. 导入ip2region.lvlib库文件;<br>
3. 查看Example.vi,了解使用方法<br>
<br>
<br>
注意:该库依赖ni_lib_unicode-2.0.1.5.vip,请使用VIPM安装。
14 changes: 13 additions & 1 deletion binding/c#/IP2Region/DBSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DbSearcher : IDisposable
/// <summary>
/// db file access handler
/// </summary>
private FileStream _raf = null;
private Stream _raf = null;

/// <summary>
/// header blocks buffer
Expand Down Expand Up @@ -75,6 +75,18 @@ public DbSearcher(DbConfig dbConfig, string dbFile)

public DbSearcher(string dbFile) : this(null, dbFile) { }

public DbSearcher(DbConfig dbConfig, Stream dbFileStream)
{
if (_dbConfig == null)
{
_dbConfig = dbConfig;
}

_raf = dbFileStream;
}

public DbSearcher(Stream dbFileStream) : this(null, dbFileStream) { }

#region Sync Methods
/// <summary>
/// Get the region with a int ip address with memory binary search algorithm.
Expand Down
Loading