当前位置: 首页>>代码示例>>Python>>正文


Python GeoIP.org_by_addr方法代码示例

本文整理汇总了Python中pygeoip.GeoIP.org_by_addr方法的典型用法代码示例。如果您正苦于以下问题:Python GeoIP.org_by_addr方法的具体用法?Python GeoIP.org_by_addr怎么用?Python GeoIP.org_by_addr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygeoip.GeoIP的用法示例。


在下文中一共展示了GeoIP.org_by_addr方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: IPToLocation

# 需要导入模块: from pygeoip import GeoIP [as 别名]
# 或者: from pygeoip.GeoIP import org_by_addr [as 别名]
def IPToLocation(ipaddr):
    city_file = os.path.join(config.advanced.geoip_data_dir, 'GeoLiteCity.dat')
    country_file = os.path.join(config.advanced.geoip_data_dir, 'GeoIP.dat')
    asn_file = os.path.join(config.advanced.geoip_data_dir, 'GeoIPASNum.dat')

    location = {'city': None, 'countrycode': None, 'asn': None}
    try:
        city_dat = GeoIP(city_file)
        try:
            location['city'] = city_dat.record_by_addr(ipaddr)['city']
        except TypeError:
            location['city'] = None
    
        country_dat = GeoIP(country_file)
        location['countrycode'] = country_dat.country_code_by_addr(ipaddr)
        if not location['countrycode']:
            location['countrycode'] = 'ZZ'

        asn_dat = GeoIP(asn_file)
        try:
            location['asn'] = asn_dat.org_by_addr(ipaddr).split(' ')[0]
        except AttributeError:
            location['asn'] = 'AS0'

    except IOError:
        log.err("Could not find GeoIP data files. Go into %s "
                "and run make geoip or change the geoip_data_dir "
                "in the config file" % config.advanced.geoip_data_dir)
        raise GeoIPDataFilesNotFound
    
    return location
开发者ID:david415,项目名称:ooni-probe,代码行数:33,代码来源:geoip.py

示例2: IPToLocation

# 需要导入模块: from pygeoip import GeoIP [as 别名]
# 或者: from pygeoip.GeoIP import org_by_addr [as 别名]
def IPToLocation(ipaddr):
    from ooni.settings import config

    country_file = config.get_data_file_path('GeoIP/GeoIP.dat')
    asn_file = config.get_data_file_path('GeoIP/GeoIPASNum.dat')

    location = {'city': None, 'countrycode': 'ZZ', 'asn': 'AS0'}

    def error():
        log.err("Could not find GeoIP data file in data directories."
                "Try running ooniresources or"
                " edit your ooniprobe.conf")

    try:
        country_dat = GeoIP(country_file)
        location['countrycode'] = country_dat.country_code_by_addr(ipaddr)
        if not location['countrycode']:
            location['countrycode'] = 'ZZ'
    except IOError:
        error()

    try:
        asn_dat = GeoIP(asn_file)
        location['asn'] = asn_dat.org_by_addr(ipaddr).split(' ')[0]
    except:
        error()

    return location
开发者ID:Samdney,项目名称:ooni-probe,代码行数:30,代码来源:geoip.py

示例3: IPToLocation

# 需要导入模块: from pygeoip import GeoIP [as 别名]
# 或者: from pygeoip.GeoIP import org_by_addr [as 别名]
def IPToLocation(ipaddr):
    from ooni.settings import config

    city_file = os.path.join(config.advanced.geoip_data_dir, 'GeoLiteCity.dat')
    country_file = os.path.join(config.advanced.geoip_data_dir, 'GeoIP.dat')
    asn_file = os.path.join(config.advanced.geoip_data_dir, 'GeoIPASNum.dat')

    location = {'city': None, 'countrycode': 'ZZ', 'asn': 'AS0'}
    
    try:
        country_dat = GeoIP(country_file)
        location['countrycode'] = country_dat.country_code_by_addr(ipaddr)
        if not location['countrycode']:
            location['countrycode'] = 'ZZ'
    except IOError:
        log.err("Could not find GeoIP data file. Go into %s "
                "and make sure GeoIP.dat is present or change the location "
                "in the config file" % config.advanced.geoip_data_dir)
    try:
        city_dat = GeoIP(city_file)
        location['city'] = city_dat.record_by_addr(ipaddr)['city']
    except:
         log.err("Could not find the city your IP is from. "
                "Download the GeoLiteCity.dat file into the geoip_data_dir"
                " or install geoip-database-contrib.")
    try:
        asn_dat = GeoIP(asn_file)
        location['asn'] = asn_dat.org_by_addr(ipaddr).split(' ')[0]
    except:
        log.err("Could not find the ASN for your IP. "
                "Download the GeoIPASNum.dat file into the geoip_data_dir"
                " or install geoip-database-contrib.")
    
    return location
开发者ID:GarysRefererence2014,项目名称:ooni-probe,代码行数:36,代码来源:geoip.py

示例4: IPToLocation

# 需要导入模块: from pygeoip import GeoIP [as 别名]
# 或者: from pygeoip.GeoIP import org_by_addr [as 别名]
def IPToLocation(ipaddr):
    from ooni.settings import config

    city_file = os.path.join(config.advanced.geoip_data_dir, 'GeoLiteCity.dat')
    country_file = os.path.join(config.advanced.geoip_data_dir, 'GeoIP.dat')
    asn_file = os.path.join(config.advanced.geoip_data_dir, 'GeoIPASNum.dat')

    location = {'city': None, 'countrycode': 'ZZ', 'asn': 'AS0'}

    def error():
        log.err("Could not find GeoIP data file in %s."
                "Try running ooniresources --update-geoip or"
                " edit your ooniprobe.conf" % config.advanced.geoip_data_dir)

    try:
        country_dat = GeoIP(country_file)
        location['countrycode'] = country_dat.country_code_by_addr(ipaddr)
        if not location['countrycode']:
            location['countrycode'] = 'ZZ'
    except IOError:
        error()

    try:
        city_dat = GeoIP(city_file)
        location['city'] = city_dat.record_by_addr(ipaddr)['city']
    except:
        error()

    try:
        asn_dat = GeoIP(asn_file)
        location['asn'] = asn_dat.org_by_addr(ipaddr).split(' ')[0]
    except:
        error()

    return location
开发者ID:kudrom,项目名称:ooni-probe,代码行数:37,代码来源:geoip.py

示例5: IPToLocation

# 需要导入模块: from pygeoip import GeoIP [as 别名]
# 或者: from pygeoip.GeoIP import org_by_addr [as 别名]
def IPToLocation(ipaddr):
    from ooni.settings import config

    country_file = config.get_data_file_path('GeoIP/GeoIP.dat')
    asn_file = config.get_data_file_path('GeoIP/GeoIPASNum.dat')

    location = {'city': None, 'countrycode': 'ZZ', 'asn': 'AS0'}
    if not asn_file or not country_file:
        log.err("Could not find GeoIP data file in data directories."
                "Try running ooniresources or"
                " edit your ooniprobe.conf")
        return location

    country_dat = GeoIP(country_file)
    asn_dat = GeoIP(asn_file)

    country_code = country_dat.country_code_by_addr(ipaddr)
    if country_code is not None:
        location['countrycode'] =  country_code

    asn = asn_dat.org_by_addr(ipaddr)
    if asn is not None:
        location['asn'] = asn.split(' ')[0]

    return location
开发者ID:Archer-sys,项目名称:ooni-probe,代码行数:27,代码来源:geoip.py

示例6: IPToLocation

# 需要导入模块: from pygeoip import GeoIP [as 别名]
# 或者: from pygeoip.GeoIP import org_by_addr [as 别名]
def IPToLocation(ipaddr):
    city_file = os.path.join(config.advanced.geoip_data_dir, 'GeoLiteCity.dat')
    country_file = os.path.join(config.advanced.geoip_data_dir, 'GeoIP.dat')
    asn_file = os.path.join(config.advanced.geoip_data_dir, 'GeoIPASNum.dat')

    location = {'city': None, 'countrycode': None, 'asn': None}
    try:
        city_dat = GeoIP(city_file)
        location['city'] = city_dat.record_by_addr(ipaddr)['city']

        country_dat = GeoIP(country_file)
        location['countrycode'] = country_dat.country_code_by_addr(ipaddr)

        asn_dat = GeoIP(asn_file)
        location['asn'] = asn_dat.org_by_addr(ipaddr).split(' ')[0]

    except IOError:
        log.err("Could not find GeoIP data files. Go into data/ "
                "and run make geoip")
        raise GeoIPDataFilesNotFound

    return location
开发者ID:rrana,项目名称:ooni-probe,代码行数:24,代码来源:geoip.py

示例7: get_isp

# 需要导入模块: from pygeoip import GeoIP [as 别名]
# 或者: from pygeoip.GeoIP import org_by_addr [as 别名]
def get_isp(ip):
    gi = GeoIP(GEO_ISP_FILE ,pygeoip.STANDARD )
    isp = gi.org_by_addr(ip)
    if isp is  None:
        isp = "Unknown"
    return isp
开发者ID:facingnorth,项目名称:dswc,代码行数:8,代码来源:service.py


注:本文中的pygeoip.GeoIP.org_by_addr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。