本文整理汇总了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
示例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
示例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
示例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
示例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
示例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
示例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