コード例 #1
0
ファイル: get.py プロジェクト: umutkirgoz/ip2info
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Jun 5, 2014
# @author Umut KIRGÖZ

import redis,time
from ip2info import IPInfo

r = redis.Redis(host = 'localhost', port = 6379, db = 8)

startTime = time.time()
ip = '194.27.203.11'
print '#'*80
print ip
print IPInfo.get(ip, r)


endTime = time.time()
print 'Process Duration : %s seconds' %(endTime-startTime)
コード例 #2
0
ファイル: import.py プロジェクト: umutkirgoz/ip2info
r = redis.Redis(host = 'localhost', port = 6379, db = 8)

r.flushdb()

pipe = r.pipeline()

filename = 'ripe.csv'
counter = 0
for line in open(filename):
    x = line.strip().split('|')
    
    rangeMin = x[0]
    rangeMax = x[1]
    rangeDesc = x[2]
    rangeCountry = x[3]
    
    if rangeMin.count('.') != 3 or rangeMax.count('.') != 3:
        print "Cannot Import: %s" %(line)
        continue
    
    print "%s--%s--%s---%s" %(rangeMin,rangeMax,rangeDesc,rangeCountry)
    range = IPInfo(rangeMin,rangeMax,rangeDesc,rangeCountry)
    range.save(pipe)
    
    counter += 1
    if counter % 5000 == 0:
        pipe.execute()
        
endTime = time.time()
print 'Process Duration : %s seconds' %(endTime-startTime)
コード例 #3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Jun 5, 2014
# @author Umut KIRGÖZ

import redis, time
from ip2info import IPInfo

r = redis.Redis(host='localhost', port=6379, db=8)

startTime = time.time()
ip = '194.27.203.11'
print '#' * 80
print ip
print IPInfo.get(ip, r)

endTime = time.time()
print 'Process Duration : %s seconds' % (endTime - startTime)