當前位置: 首頁>>代碼示例>>Python>>正文


Python pygeoip.GeoIP方法代碼示例

本文整理匯總了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 
開發者ID:mitodl,項目名稱:edx2bigquery,代碼行數:18,代碼來源:make_geoip_table.py

示例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) 
開發者ID:edx,項目名稱:edx-analytics-pipeline,代碼行數:19,代碼來源:geolocation.py

示例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
#---------------------------------------------------------------------- 
開發者ID:kevthehermit,項目名稱:dc-toolkit,代碼行數:18,代碼來源:DC_dbparser.py

示例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 = "查詢")

    # 完成布局 
開發者ID:zhaoolee,項目名稱:PythonGUIDemo,代碼行數:18,代碼來源:011根據ip查詢地理位置.py

示例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 
開發者ID:projectarkc,項目名稱:arkc-client,代碼行數:23,代碼來源:dnsproxy.py

示例6: get_geoip

# 需要導入模塊: import pygeoip [as 別名]
# 或者: from pygeoip import GeoIP [as 別名]
def get_geoip():
    return pygeoip.GeoIP("GeoLiteCity.dat")

#打印IP信息 
開發者ID:sunshinelyz,項目名稱:python-hacker,代碼行數:6,代碼來源:search_ip_geolitecity.py

示例7: main

# 需要導入模塊: import pygeoip [as 別名]
# 或者: from pygeoip import GeoIP [as 別名]
def main():
    #實例化GeoIP對象
    gi = get_geoip()
    search_ip_info(gi) 
開發者ID:sunshinelyz,項目名稱:python-hacker,代碼行數:6,代碼來源:search_ip_geolitecity.py

示例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 !" 
開發者ID:medbenali,項目名稱:CyberScan,代碼行數:39,代碼來源:CyberScan.py

示例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)) 
開發者ID:PacktPublishing,項目名稱:Learning-Python-Networking-Second-Edition,代碼行數:7,代碼來源:pygeoip_test.py

示例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)) 
開發者ID:PacktPublishing,項目名稱:Learning-Python-Networking-Second-Edition,代碼行數:7,代碼來源:pygeoip_test.py

示例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 
開發者ID:hacktoolkit,項目名稱:django-htk,代碼行數:9,代碼來源:utils.py

示例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 
開發者ID:hacktoolkit,項目名稱:django-htk,代碼行數:9,代碼來源:utils.py

示例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 
開發者ID:hacktoolkit,項目名稱:django-htk,代碼行數:12,代碼來源:utils.py

示例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 
開發者ID:SpamExperts,項目名稱:OrangeAssassin,代碼行數:10,代碼來源:relay_country.py

示例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") 
開發者ID:ex0dus-0x,項目名稱:doxbox,代碼行數:29,代碼來源:run.py


注:本文中的pygeoip.GeoIP方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。