本文整理汇总了Python中GeoIP.open方法的典型用法代码示例。如果您正苦于以下问题:Python GeoIP.open方法的具体用法?Python GeoIP.open怎么用?Python GeoIP.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeoIP
的用法示例。
在下文中一共展示了GeoIP.open方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import GeoIP [as 别名]
# 或者: from GeoIP import open [as 别名]
def __init__(self, conf=config, dat_file=MAXMIND_FILE):
try:
maxmind_file = config.get('Configuration', 'dat_file')
if maxmind_file[0] != "/":
maxmind_file = loc + maxmind_file
#print maxmind_file # DEBUG
self.gi = GeoIP.open(maxmind_file, GeoIP.GEOIP_STANDARD)
self.dat_file_success = True
except:
pass
if not self.dat_file_success:
try:
if dat_file[0] != "/":
dat_file = loc + dat_file
#print dat_file # DEBUG
self.gi = GeoIP.open(dat_file, GeoIP.GEOIP_STANDARD)
self.dat_file_success = True
except:
pass
示例2: createKML
# 需要导入模块: import GeoIP [as 别名]
# 或者: from GeoIP import open [as 别名]
def createKML(iplist):
fname = raw_input('KML Output Filename : ')
if fname.endswith('.kml'):
pass
else:
fname += '.kml'
global fnp
fnp = open(fname, 'w')
fnp.write('<?xml version="1.0" encoding="UTF-8"?>\n'
'<kml xmlns="http://www.opengis.net/kml/2.2"><Document>\n')
for ip in iplist:
if ':' in ip:
pmEntry(ip.split(':')[0])
else:
pmEntry(ip[:-1])
fnp.write('</Document></kml>\n')
fnp.close()
示例3: __init__
# 需要导入模块: import GeoIP [as 别名]
# 或者: from GeoIP import open [as 别名]
def __init__(self, **kwargs):
self.kwargs = kwargs
self.ASN_DB = os.getenv('ISOLATE_GEOIP_ASN', '/opt/auth/shared/geoip/GeoIPASNum.dat')
self.asn = GeoIP.open(self.ASN_DB, GeoIP.GEOIP_STANDARD)
示例4: _init_readers
# 需要导入模块: import GeoIP [as 别名]
# 或者: from GeoIP import open [as 别名]
def _init_readers(self):
self.g1_asnum_reader = GeoIP.open(self.v1_asnum, GeoIP.GEOIP_STANDARD)
self.g1_city_reader = GeoIP.open(self.v1_city, GeoIP.GEOIP_STANDARD)
self.g1_country_reader = GeoIP.open(
self.v1_country,
GeoIP.GEOIP_STANDARD
)
示例5: ip2geo
# 需要导入模块: import GeoIP [as 别名]
# 或者: from GeoIP import open [as 别名]
def ip2geo(ip):
gi = GeoIP.open(geoDBpath,GeoIP.GEOIP_STANDARD)
gs = gi.record_by_addr(ip)
return gs
示例6: TraceTarget
# 需要导入模块: import GeoIP [as 别名]
# 或者: from GeoIP import open [as 别名]
def TraceTarget(target_ip,interface):
results = execute_command(["itrace","-i",interface,"-d",target_ip])
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPCity.dat",GeoIP.GEOIP_STANDARD)
i = 0
for line in results:
if not line is "":
#print line
lst = list(str(line).split())
if not lst[1]=="Timeout":
#remove "[" and "]" at start and end of the string
i = i + 1
ipadr = str(str(lst[1]).replace("[","")).replace("]","")
try:
gir = gi.record_by_addr(ipadr)
if gir != None:
r = [i, ipadr, gir['country_code'], gir['city'], round(float(gir['latitude']),2), round(float(gir['longitude']),2)]
else:
r = [i, ipadr, "N/A", "N/A", "N/A", "N/A"]
except:
r = [i, ipadr, "N/A", "N/A", "N/A", "N/A"]
print str(r[0]).ljust(4)+str(r[1]).ljust(17)+str(r[2]).ljust(6)+str(r[3]).ljust(30)+str(r[4]).rjust(10)+str(r[5]).rjust(10)
###############################################################################
# PROCESS HANDLER #
###############################################################################
示例7: geoIp
# 需要导入模块: import GeoIP [as 别名]
# 或者: from GeoIP import open [as 别名]
def geoIp(IP):
#return urllib.urlopen("http://ip-api.com/json/" + str(IP))
gi = GeoIP.open("/usr/share/GeoIP/GeoIPCity.dat", GeoIP.GEOIP_STANDARD)
gir = gi.record_by_addr(IP)
print gir
return gir
示例8: __init__
# 需要导入模块: import GeoIP [as 别名]
# 或者: from GeoIP import open [as 别名]
def __init__(self, config):
self.config = config
self.host_url = "http://updates.maxmind.com"
self.fnames_url = "%s/app/update_getfilename" % self.host_url
self.ipaddr_url = "%s/app/update_getipaddr" % self.host_url
self.update_url = "%s/app/update_secure" % self.host_url
self.db_path = "%s/geo_db" % TS_DIR
self.db_hashes = {}
self.v1_asnum = "%s/GeoLiteASNum.dat" % self.db_path
self.v1_city = "%s/GeoLiteCity.dat" % self.db_path
self.v1_country = "%s/GeoLiteCountry.dat" % self.db_path
self.g1_asnum_reader = None
self.g1_city_reader = None
self.g1_country_reader = None
self.have_db_files = True
if not os.path.exists(self.db_path):
value = raw_input(
bold(
red(
"Geolocation databases not found. Would you like " +
"to download them now ([yes]/no)?: "
)
)
)
value = value.strip().upper()
if(
value == "NO" or
value == "N"
):
self.have_db_files = False
else:
os.mkdir(self.db_path)
self.update()
else:
db_files = glob.glob("%s/*" % self.db_path)
for db_file in db_files:
db_data = open(db_file).read()
db_hash = md5(db_data).hexdigest()
db_file = db_file.split(os.path.sep)[-1]
self.db_hashes[db_file] = db_hash
if db_files:
self._init_readers()
示例9: main
# 需要导入模块: import GeoIP [as 别名]
# 或者: from GeoIP import open [as 别名]
def main():
global portList, totalPuertos, ip_address
f = open("dic/targets.txt", "r")
targets = f.readlines()
for target in targets:
target = target.strip()
if not target or target.startswith("#"):
continue
if is_valid_cidr(target):
for ip_address in netaddr.IPNetwork(target):
ip_address = str(ip_address)
print "----------------------------------------"
print "[INFO] Connecting to: " + str(ip_address)
for port in portList:
global _lastlocation
_lastlocation = ''
pct = str(porcentaje(portList.index(port)))
print "|----[!] " + str(ip_address) + " -> " + str(port) + " " + pct + "%"
# Obtenemos el mensaje del servidor en el puerto
webport = [80, 8080, 443, 28017]
if port in webport:
Banner = banner_grabbing_web(ip_address, port)
elif port == 27017:
Banner = banner_grabbing_mongo(ip_address, port)
else:
Banner = banner_grabbing(ip_address, port)
if Banner == "none":
pass
else:
print "[+]" + ip_address + ' : ' + str(port) + ' -BANNER- \n' + Banner + time.strftime("%H:%M:%S") + ' '
# Variables obtenidas de la geoIp
data_geoIP = geoIp(ip_address)
if data_geoIP:
Country = data_geoIP["country_name"]
City = data_geoIP["city"]
regionName = data_geoIP["region_name"]
# ISP = data_geoIP["isp"]
Latitud = data_geoIP["latitude"]
Longitud = data_geoIP["longitude"]
ISP = "null"
else:
Country = City = regionName = ISP = Latitud = Longitud = "null"
date_Insert = time.strftime("%H:%M:%S")
date_Update = "none"
insert_mongodb(ip_address, Country, City, regionName, ISP, port, Banner, Latitud, Longitud, date_Insert, date_Update)
break
else:
print "[ERROR] Invalid target: " + target