forked from funsim/cpp_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxmind_test.py
53 lines (46 loc) · 1.07 KB
/
maxmind_test.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
#!/usr/bin/python
#
# maxmind_test.py
#
# A test script for the maxmind class
#
# Initials:
# AX Axel Roest
#
# Version history
# 20120710 AR first version
#
# ToDO:
#
import sys
import re
import os
import math
import bisect
from datetime import datetime
import MySQLdb
import random
from maxmind import MaxMind
# test
mm = MaxMind(db_host, db_user, db_passwd, db_name, db_filetable)
ip = 67276848
loc = mm.lookup(ip)
print str(ip) + ' : ' + str(loc)
ip = 67277000
loc = mm.lookup(ip)
print str(ip) + ' : ' + str(loc)
ip = 67277023
loc = mm.lookup(ip)
print str(ip) + ' : ' + str(loc)
ip = 67277024
loc = mm.lookup(ip)
print str(ip) + ' : ' + str(loc)
testamount = 100000
start_time = datetime.now()
for i in range(testamount):
r = random.randint(33996344, 3741319167)
loc = mm.lookup(r)
end_time = datetime.now()
totaltime = end_time - start_time
timeperlookup = totaltime / testamount
print '=====================================\nLookup ' + str(testamount) + ' ips in ' + str(totaltime) + ' seconds = ' + str(timeperlookup) + ' seconds per lookup'