本文整理汇总了Python中pygeoip.GeoIP方法的典型用法代码示例。如果您正苦于以下问题:Python pygeoip.GeoIP方法的具体用法?Python pygeoip.GeoIP怎么用?Python pygeoip.GeoIP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygeoip
的用法示例。
在下文中一共展示了pygeoip.GeoIP方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def __init__(self, gipdataset=GIPDATASET, giptable=GIPTABLE, geoipdat='GeoIP2-City.mmdb', version=2):
# geoip version 1: GeoIPCity.dat
# geoip version 2: GeoIP2-City.mmdb
if not os.path.exists(geoipdat):
raise Exception("---> [make_geoip_table] Error! Missing file %s for local geoip" % geoipdat)
self.gipdataset = gipdataset
self.giptable = giptable
self.gipfn = self.giptable + ".json"
self.version = version
if version==1:
self.gi = pygeoip.GeoIP(geoipdat, pygeoip.MEMORY_CACHE)
else:
self.gi = geoip2.database.Reader(geoipdat)
self.nchanged = 0
示例2: init_reducer
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def init_reducer(self):
"""Initialize the geolocation object for use by a reducer."""
super(GeolocationMixin, self).init_reducer()
# Copy the remote version of the geolocation data file to a local file.
# This is required by the GeoIP call, which assumes that the data file is located
# on a local file system.
self.temporary_data_file = tempfile.NamedTemporaryFile(prefix='geolocation_data')
with self.geolocation_data_target().open() as geolocation_data_input:
while True:
transfer_buffer = geolocation_data_input.read(1024)
if transfer_buffer:
self.temporary_data_file.write(transfer_buffer)
else:
break
self.temporary_data_file.seek(0)
self.geoip = pygeoip.GeoIP(self.temporary_data_file.name, pygeoip.STANDARD)
示例3: geo_ip
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def geo_ip(res_type, ip):
try:
import pygeoip
gi = pygeoip.GeoIP('GeoIP.dat')
if res_type == 'name':
return gi.country_name_by_addr(ip)
if res_type == 'cc':
return gi.country_code_by_addr(ip)
return gi.country_code_by_addr(ip)
except Exception as e:
print e
return ''
#----------------------------------------------------------------------
# Search
#----------------------------------------------------------------------
示例4: __init__
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def __init__(self):
self.gi = pygeoip.GeoIP("./GeoLiteCity.dat")
# 创建主窗口,用于容纳其它组件
self.root = tkinter.Tk()
# 给主窗口设置标题内容
self.root.title("全球定位ip位置(离线版)")
# 创建一个输入框,并设置尺寸
self.ip_input = tkinter.Entry(self.root,width=30)
# 创建一个回显列表
self.display_info = tkinter.Listbox(self.root, width=50)
# 创建一个查询结果的按钮
self.result_button = tkinter.Button(self.root, command = self.find_position, text = "查询")
# 完成布局
示例5: __init__
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def __init__(self, *args, **kwargs):
dns_blacklist = kwargs.pop('dns_blacklist')
dns_servers = kwargs.pop('dns_servers')
dns_tcpover = kwargs.pop('dns_tcpover', [])
dns_timeout = kwargs.pop('dns_timeout', 2)
super(self.__class__, self).__init__(*args, **kwargs)
self.dns_servers = list(dns_servers)
self.dns_tcpover = tuple(dns_tcpover)
self.dns_intranet_servers = [x for x in self.dns_servers if is_local_addr(x)]
self.dns_blacklist = set(dns_blacklist)
self.dns_timeout = int(dns_timeout)
self.dns_cache = ExpireCache(max_size=65536)
self.dns_trust_servers = set(['8.8.8.8', '8.8.4.4', '2001:4860:4860::8888', '2001:4860:4860::8844'])
for dirname in ('.', '/usr/share/GeoIP/', '/usr/local/share/GeoIP/'):
filename = os.path.join(dirname, 'GeoIP.dat')
if os.path.isfile(filename):
geoip = pygeoip.GeoIP(filename)
for dnsserver in self.dns_servers:
if ':' not in dnsserver and geoip.country_name_by_addr(parse_hostport(dnsserver, 53)[0]) not in ('China',):
self.dns_trust_servers.add(dnsserver)
break
示例6: get_geoip
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def get_geoip():
return pygeoip.GeoIP("GeoLiteCity.dat")
#打印IP信息
示例7: main
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def main():
#实例化GeoIP对象
gi = get_geoip()
search_ip_info(gi)
示例8: geo_ip
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def geo_ip(host):
try:
rawdata = pygeoip.GeoIP('GeoLiteCity.dat')
data = rawdata.record_by_name(host)
country = data['country_name']
city = data['city']
longi = data['longitude']
lat = data['latitude']
time_zone = data['time_zone']
area_code = data['area_code']
country_code = data['country_code']
region_code = data['region_code']
dma_code = data['dma_code']
metro_code = data['metro_code']
country_code3 = data['country_code3']
zip_code = data['postal_code']
continent = data['continent']
print '[*] IP Address: ',host
print '[*] City: ',city
print '[*] Region Code: ',region_code
print '[*] Area Code: ',area_code
print '[*] Time Zone: ',time_zone
print '[*] Dma Code: ',dma_code
print '[*] Metro Code: ',metro_code
print '[*] Latitude: ',lat
print '[*] Longitude: ',longi
print '[*] Zip Code: ',zip_code
print '[*] Country Name: ',country
print '[*] Country Code: ',country_code
print '[*] Country Code3: ',country_code3
print '[*] Continent: ',continent
except :
print "[*] Please verify your ip !"
示例9: geoip_city
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def geoip_city(domain,ipaddress):
path = 'GeoLiteCity.dat'
gic = pygeoip.GeoIP(path)
print(gic.record_by_addr(ipaddress))
print(gic.region_by_name(domain))
示例10: geoip_country
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def geoip_country(domain,ipaddress):
path = 'GeoIP.dat'
gi = pygeoip.GeoIP(path)
print(gi.country_code_by_name(domain))
print(gi.country_name_by_addr(ipaddress))
示例11: get_geoip_country
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def get_geoip_country():
geoip_country_db = htk_setting('HTK_LIB_GEOIP_COUNTRY_DB')
if geoip_country_db:
gi_country = pygeoip.GeoIP(geoip_country_db)
else:
gi_country = None
return gi_country
示例12: get_geoip_city
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def get_geoip_city():
geoip_city_db = htk_setting('HTK_LIB_GEOIP_CITY_DB')
if geoip_city_db:
gi_city = pygeoip.GeoIP(geoip_city_db)
else:
gi_city = None
return gi_city
示例13: get_record_by_ip
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def get_record_by_ip(ip):
"""Returns dictionary with city data containing country_code, country_name, region, city, postal_code, latitude, longitude, dma_code, metro_code, area_code, region_code and time_zone.
http://pygeoip.readthedocs.io/en/v0.3.2/api-reference.html#pygeoip.GeoIP.record_by_addr
"""
gi_city = get_geoip_city()
record = {}
if gi_city:
record = gi_city.record_by_addr(ip)
return record
示例14: load_database
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def load_database(self, which=""):
"""Load the csv file and create a list of items where to search the IP.
"""
try:
return pygeoip.GeoIP(self["geodb" + which])
except IOError as exc:
self.ctxt.log.warning("Unable to open geo database file: %r", exc)
return None
示例15: geoip
# 需要导入模块: import pygeoip [as 别名]
# 或者: from pygeoip import GeoIP [as 别名]
def geoip():
description = """
When working with metadata, IP addresses often pop up as a point-of-interest.
Using Maxmind and Google Map's APIs, the GeoIP module aims to collect geolocation
information on public IP addresses, in order to gather data on physical location during
the reconaissance stage of the killchain. In order to make this module work, please provide a
Google Maps API key."""
form = forms.GeoIPForm()
if flask.request.method == "POST":
geoip = pygeoip.GeoIP("extras/GeoLiteCity.dat")
try:
ip_data = geoip.record_by_addr(flask.request.form['ip'])
return flask.render_template('geoip.html',
title="GeoIP Module", user=user, description=description, form=form,
latitude=ip_data["latitude"], longitude=ip_data["longitude"], ip_data=ip_data)
except (TypeError, ValueError, socket.error):
flask.flash("Invalid IP Address provided!", "danger")
return flask.redirect(flask.url_for('geoip'))
else:
return flask.render_template('geoip.html',
title="GeoIP Module", small="Using locational data to conduct info-gathering",
user=user, description=description, form=form,
latitude="0", longitude="0")