зеркало из https://github.com/mozilla/MozDef.git
Merge pull request #905 from mozilla/fix_geo_db_location
Fix geolite db location
This commit is contained in:
Коммит
800f595023
|
@ -124,7 +124,8 @@ def isIP(ip):
|
|||
def ipLocation(ip):
|
||||
location = ""
|
||||
try:
|
||||
geoip = GeoIP()
|
||||
geoip_data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../data/GeoLite2-City.mmdb")
|
||||
geoip = GeoIP(geoip_data_dir)
|
||||
geoDict = geoip.lookup_ip(ip)
|
||||
if geoDict is not None:
|
||||
if 'error' in geoDict:
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
import os
|
||||
import geoip2.database
|
||||
|
||||
|
||||
class GeoIP(object):
|
||||
def __init__(self, db_location=None):
|
||||
if db_location is None:
|
||||
db_location = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../data/GeoLite2-City.mmdb")
|
||||
def __init__(self, db_location):
|
||||
try:
|
||||
self.db = geoip2.database.Reader(db_location)
|
||||
except IOError:
|
||||
|
|
|
@ -56,6 +56,6 @@ setup(
|
|||
test_suite='tests',
|
||||
tests_require=[],
|
||||
url='https://github.com/mozilla/MozDef/tree/master/lib',
|
||||
version='1.0.1',
|
||||
version='1.0.2',
|
||||
zip_safe=False,
|
||||
)
|
||||
|
|
|
@ -27,7 +27,8 @@ class message(object):
|
|||
'''
|
||||
self.registration = ['sourceipaddress', 'destinationipaddress']
|
||||
self.priority = 20
|
||||
self.geoip = GeoIP()
|
||||
geoip_data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../data/GeoLite2-City.mmdb")
|
||||
self.geoip = GeoIP(geoip_data_dir)
|
||||
|
||||
def ipLocation(self, ip):
|
||||
location = dict()
|
||||
|
|
|
@ -33,7 +33,7 @@ KitnIRC==0.2.6
|
|||
kombu==4.1.0
|
||||
meld3==1.0.2
|
||||
mozdef-client==1.0.11
|
||||
mozdef-util==1.0.1
|
||||
mozdef-util==1.0.2
|
||||
MySQL-python==1.2.5
|
||||
netaddr==0.7.1
|
||||
nose==1.3.7
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
import os
|
||||
import sys
|
||||
from mozdef_util.geo_ip import GeoIP
|
||||
|
||||
|
||||
class TestGeoIPLookup(object):
|
||||
def setup(self):
|
||||
self.geo_ip = GeoIP()
|
||||
|
||||
# Unfortunately since the db file is not present by default
|
||||
# we verify the error
|
||||
def test_without_db_file(self):
|
||||
geo_dict = self.geo_ip.lookup_ip('129.21.1.40')
|
||||
geo_ip = GeoIP("nonexistent_db")
|
||||
geo_dict = geo_ip.lookup_ip('129.21.1.40')
|
||||
assert geo_dict['error'] == 'No Geolite DB Found!'
|
||||
|
|
Загрузка…
Ссылка в новой задаче