Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit784579f

Browse files
committed
update
1 parent52c4444 commit784579f

File tree

3 files changed

+101
-9
lines changed

3 files changed

+101
-9
lines changed

‎README_en.md‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#ipdb-python
2+
IPIP.net officially supported IP database ipdb format parsing library
3+
4+
#Python Parse ipdb file
5+
6+
##Installing
7+
<pre>
8+
<code>pip install ipip-ipdb</code>
9+
</pre>
10+
11+
##Dependents ( python 2.x or before python 3.3 )
12+
<pre><code>pip install ipaddress</code></pre>
13+
14+
##Code Example
15+
<pre><code>
16+
import ipdb
17+
18+
db = ipdb.City("/path/to/city.ipv4.ipdb")
19+
# db.reload("/path/to/city.ipv4.ipdb") # update ipdb database file reload data
20+
print(db.is_ipv4(), db.is_ipv6())
21+
print(db.languages()) # support language
22+
print(db.fields()) # support fields
23+
print(db.build_time()) # build database time
24+
print(db.find("1.1.1.1", "CN")) # query ip return array
25+
# print(db.find(u"1.1.1.1", "CN")) # Python 2.7
26+
print(db.find_map("8.8.8.8", "CN")) # query ip return dict
27+
print(db.find_info("118.28.1.1", "CN").country_name)
28+
</pre></code>
29+
30+
###IPDB Database Fields:
31+
<pre>
32+
country_name : Country Name
33+
region_name : Province Name
34+
city_name : City Name
35+
owner_domain : Domain of IP owner
36+
isp_domain : ISP of IP being broadcasted
37+
latitude : Latitude
38+
longitude : Longitude
39+
timezone : Timezone
40+
utc_offset : UTC time standard offset
41+
china_admin_code : China administrative divisions code
42+
idd_code : International Dialling Codes
43+
country_code : Two-letter country codes based on ISO 3166.
44+
continent_code : Regional Internet registry code.
45+
idc : IDC label
46+
base_station : Basestation label
47+
country_code3 : Three-letter country codes based on ISO 3166.
48+
european_union : European union label
49+
currency_code : Currency Code
50+
currency_name : Currency Name
51+
anycast : ANYCAST label
52+
53+
</pre>
54+
55+
###IPDB CN District sample code :
56+
<pre>
57+
import ipdb
58+
59+
db = ipdb.District("/path/to/china_district.ipdb")
60+
print(db.is_ipv4(), db.is_ipv6())
61+
print(db.languages())
62+
print(db.fields())
63+
print(db.build_time())
64+
print(db.find("1.12.13.255", "CN"))
65+
print(db.find_map("1.12.13.255", "CN"))
66+
print(db.find_info("1.12.13.255", "CN").country_name)
67+
</pre>
68+
69+
###IPDB Basestation sample code :
70+
<pre>
71+
import ipdb
72+
db = ipdb.BaseStation("/path/to/base_station.ipdb")
73+
print(db.is_ipv4(), db.is_ipv6())
74+
print(db.languages())
75+
print(db.fields())
76+
print(db.build_time())
77+
print(db.find_map("117.136.83.55", "CN"))
78+
</pre>

‎example.py‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__importunicode_literals
22
importipdb,sys
33

4+
importpandasaspd
45

56

67
deftest_free():
@@ -31,14 +32,27 @@ def test_city_ipv4():
3132
print(db.find_map("8.8.8.8","CN"))
3233
print(db.find_info("118.28.1.1","CN").country_name)
3334

35+
importipaddress
36+
37+
deftest_city_ipv6_test():
38+
39+
db=ipdb.City("c:/work/ipdb/mydata6vipday2.ipdb")
40+
41+
print(db.find("2001:44c8:4644:1191:3c41:724d:e391:51b0","CN"))
42+
print(db.find_map("2a04:3543:1000:2310:ecb3:3eff:fef0:20e1","CN"))
43+
print(db.find_info("2a04:3543:1000:2310:ecb3:3eff:fef0:20e1","CN").country_name)
3444

3545
deftest_city_ipv6():
36-
db=ipdb.City("c:/work/ipdb/city.ipv6.ipdb")
37-
print(db.is_ipv4(),db.is_ipv6())
38-
print(db.languages())
39-
print(db.fields())
40-
print(db.build_time())
41-
print(db.find("2001:250:200::","CN"))
46+
db4=ipdb.City("c:/tiantexin/download/mydata4vipday4_cn.ipdb")
47+
db=ipdb.City("c:/work/ipdb/mydata6vipday2.ipdb")
48+
49+
df=pd.read_csv("C:\\Users\\GAOCHUNHUI\\Documents\\WeChat Files\\daxime\\FileStorage\\File\\2019-10\\ipiptest\\ip_data.csv")
50+
fori,rowindf.iterrows():
51+
ifipaddress.ip_address(row['request_ip']).version==4:
52+
53+
db4.find(row['request_ip'],"CN")
54+
else:
55+
print(db.find(row['request_ip'],"CN"),row['request_ip'])
4256

4357
try:
4458
print(db.find("2000:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF","CN"))
@@ -84,7 +98,7 @@ def test_idc_list():
8498
print(db.find_map("8.8.8.8","CN"))
8599

86100
# test_city_ipv4()
87-
#test_city_ipv6()
101+
#test_city_ipv6_test()
88102
# test_base_station()
89-
test_district()
103+
test_city_ipv6()
90104
# test_city_ipv4()

‎ipdb/database.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _find_node(self, ip):
8989
break
9090
node=self._read_node(node, (1& (packed[idx>>3]>>7- (idx%8))))
9191
idx+=1
92-
ifidx==16:
92+
ifidx==16andbit_count==128:
9393
self._v6offsetCache[key]=node
9494

9595
ifnode>self._meta.node_count:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp