#NEWLINE# def add( self , ip , source , description , priority = 1 , reputation = 1 , latitude = 0.0 , longitude = 0.0 , city = '' , country = '' ) : #NEWLINE# #INDENT# '\n\n        :param string ip: IP is a dotted quad x.x.x.x or CIDR x.x.x.x/yy\n        :param string source: Source for ThreatDB entry URL\n        :param string description: Description of this individual entry\n        :param int priority: Priority of threat\n        :param int reputation: Reputation of threat\n        :param float latitude: Latitude of threat entry\n        :param float longitude: Longitude of threat entry\n        :param string city: City of located threat\n        :param string country: Country of located threat\n        :return:\n        ' #NEWLINE# if ( not re . match ( re_ipcidr , ip ) ) : #NEWLINE# #INDENT# raise Exception ( ValueError , ( 'IP %s is not valid' % ip ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# reader = get_geo_db ( ) #NEWLINE# response = reader . city ( netaddr . IPNetwork ( ip ) . network ) #NEWLINE# if ( not city ) : #NEWLINE# #INDENT# city = response . city . name #NEWLINE# #UNINDENT# if ( not country ) : #NEWLINE# #INDENT# country = response . country . name #NEWLINE# #UNINDENT# if ( not reputation ) : #NEWLINE# #INDENT# if response . location . latitude : #NEWLINE# #INDENT# latitude = response . location . latitude #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# latitude = 0 #NEWLINE# #UNINDENT# #UNINDENT# if ( not longitude ) : #NEWLINE# #INDENT# if response . location . longitude : #NEWLINE# #INDENT# longitude = response . location . longitude #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# longitude = 0 #NEWLINE# #UNINDENT# #UNINDENT# reader . close ( ) #NEWLINE# #UNINDENT# except geoip2 . errors . AddressNotFoundError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except maxminddb . errors . InvalidDatabaseError as e : #NEWLINE# #INDENT# raise ( 'Invalid GeoIP database %s' % e ) #NEWLINE# #UNINDENT# if ( ( latitude < ( - 90.0 ) ) or ( latitude > 90.0 ) ) : #NEWLINE# #INDENT# latitude = 0 #NEWLINE# #UNINDENT# if ( ( longitude < ( - 180.0 ) ) or ( longitude > 180.0 ) ) : #NEWLINE# #INDENT# longitude = 0 #NEWLINE# #UNINDENT# for i in netaddr . IPNetwork ( ip ) : #NEWLINE# #INDENT# self . entries . append ( { #NEWLINE# #INDENT# 'ip' : i , #NEWLINE# 'source' : source , #NEWLINE# 'description' : description , #NEWLINE# 'priority' : priority , #NEWLINE# 'reputation' : reputation , #NEWLINE# 'latitude' : latitude , #NEWLINE# 'longitude' : longitude , #NEWLINE# 'city' : city , #NEWLINE# 'country' : country , #NEWLINE# #UNINDENT# } )