本文整理汇总了Python中ipwhois.IPWhois.get方法的典型用法代码示例。如果您正苦于以下问题:Python IPWhois.get方法的具体用法?Python IPWhois.get怎么用?Python IPWhois.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipwhois.IPWhois
的用法示例。
在下文中一共展示了IPWhois.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _rezo
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import get [as 别名]
def _rezo():
_html = []
if request.headers.getlist("X-Forwarded-For"):
_ip = request.headers.getlist("X-Forwarded-For")[0]
else:
_ip = request.remote_addr
_html.extend([ "<center><h1 name=ip>", _ip, "</h1><p><br>" ])
if _ip != "127.0.0.1":
if not IPAddress(_ip).is_private():
_ip_info = IPWhois(_ip).lookup_rdap(depth=1)
_entity = _ip_info.get('entities')[0]
_html.extend([ _ip_info.get('network').get('name'), "<br>",
_ip_info.get('network').get('cidr'), "<br>",
_ip_info.get('network').get('handle'), "<br>",
_ip_info.get('network').get('links')[0], "<br>" ])
_html.append(_ip_info.get('objects').get(_entity).get('contact').get('address')[0].get('value'))
return _html
示例2: check_ip
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import get [as 别名]
def check_ip(ip):
from app.models.models import Ip
ip_inst = db_session.session.query(Ip).get(ip)
if ip_inst:
return ip_inst
ip_data = IPWhois(ip).lookup()
ip_inst = Ip(ip=ip,
provider_id=_get_provider(ip_data.get('asn')),
country_id=ip_data['nets'][0]['country'],
description=ip_data['nets'][0]['description'])
db_session.session.add(ip_inst)
return ip_inst
示例3: get_whois_tags
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import get [as 别名]
def get_whois_tags(ip_address):
"""
Get list of tags with `address` for given `ip_address`.
Args:
index_page (str): HTML content of the page you wisht to analyze.
Returns:
list: List of :class:`.SourceString` objects.
"""
whois = IPWhois(ip_address).lookup_whois()
nets = whois.get("nets", None)
if not nets:
return []
# parse cities
cities = [
net["city"]
for net in nets
if net.get("city", None)
]
# parse address tags
address_list = []
for net in nets:
address = net.get("address", None)
if not address:
continue
# filter company name
if "description" in net and net["description"]:
address = address.replace(net["description"], "").strip()
if "\n" in address:
address = ", ".join(address.splitlines())
address_list.append(address)
return [
SourceString(val, source="Whois")
for val in set(cities + address_list)
]