forked from ipipdotnet/ipdb-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
90 lines (71 loc) · 2.34 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from __future__ import unicode_literals
import ipdb,sys
def test_free():
db = ipdb.City("c:/work/ipdb/mydata4vipweek2.ipdb")
print(db.is_ipv4(), db.is_ipv6())
print(db.languages())
print(db.fields())
print(db.build_time())
print(db.find("1.1.1.1", "CN"))
print("ipdb reload", db.reload("c:/work/ipdb/city.free.ipdb"))
print(db.find("118.28.1.1", "CN"))
try:
print(db.find("2000:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", "CN"))
except Exception as e:
print(e)
def test_city_ipv4():
db = ipdb.City("c:/tiantexin/download/mydata4vipday4_cn.ipdb")
print(db.is_ipv4(), db.is_ipv6())
print(db.languages())
print(db.fields())
print(db.build_time())
print(db.find("1.1.1.1", "CN"))
print(db.find_map("8.8.8.8", "CN"))
print(db.find_info("118.28.1.1", "CN").country_name)
def test_city_ipv6():
db = ipdb.City("c:/work/ipdb/city.ipv6.ipdb")
print(db.is_ipv4(), db.is_ipv6())
print(db.languages())
print(db.fields())
print(db.build_time())
print(db.find("2001:250:200::", "CN"))
try:
print(db.find("2000:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", "CN"))
except Exception as e:
print(e)
def test_district():
db = ipdb.District("c:/work/ipdb/china_district.ipdb")
print(db.is_ipv4(), db.is_ipv6())
print(db.languages())
print(db.fields())
print(db.build_time())
for A in range(223):
for B in range (255):
try:
print(db.find("%d.%d.114.144" % (A, B), "CN"))
except ipdb.IPNotFound as e:
print(e)
try:
print(db.find("1.1.1.1", "CN"))
except ipdb.IPNotFound as e: # ip not found
print(e)
except ipdb.DatabaseError as e: # database file size error
print(e)
print(db.find_map("1.12.13.255", "CN"))
print(db.find_info("1.12.13.255", "CN").country_name)
def test_base_station():
db = ipdb.BaseStation("c:/work/ipdb/base_station.ipdb")
print(db.is_ipv4(), db.is_ipv6())
print(db.languages())
print(db.fields())
print(db.build_time())
print(db.find_map("117.136.83.55", "CN"))
def test_idc_list():
db = ipdb.IDC("c:/work/ipdb/idc_list.ipdb")
print(db.find_map("1.1.1.1", "CN"))
print(db.find_map("8.8.8.8", "CN"))
# test_city_ipv4()
# test_city_ipv6()
# test_base_station()
test_district()
# test_city_ipv4()