本文整理汇总了Python中socket.AI_NUMERICHOST属性的典型用法代码示例。如果您正苦于以下问题:Python socket.AI_NUMERICHOST属性的具体用法?Python socket.AI_NUMERICHOST怎么用?Python socket.AI_NUMERICHOST使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socket
的用法示例。
在下文中一共展示了socket.AI_NUMERICHOST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_valid_ip
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def is_valid_ip(ip):
"""Returns true if the given string is a well-formed IP address.
Supports IPv4 and IPv6.
"""
if not ip or '\x00' in ip:
# getaddrinfo resolves empty strings to localhost, and truncates
# on zero bytes.
return False
try:
res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror as e:
if e.args[0] == socket.EAI_NONAME:
return False
raise
return True
示例2: is_valid_ip
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def is_valid_ip(ip):
"""Returns true if the given string is a well-formed IP address.
Supports IPv4 and IPv6.
//取自 tornado
"""
if not ip or '\x00' in ip:
# getaddrinfo resolves empty strings to localhost, and truncates
# on zero bytes.
return False
try:
res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror as e:
if e.args[0] == socket.EAI_NONAME:
return False
raise
return True
示例3: is_valid_ip
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def is_valid_ip(ip: str) -> bool:
"""Returns ``True`` if the given string is a well-formed IP address.
Supports IPv4 and IPv6.
"""
if not ip or "\x00" in ip:
# getaddrinfo resolves empty strings to localhost, and truncates
# on zero bytes.
return False
try:
res = socket.getaddrinfo(
ip, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST
)
return bool(res)
except socket.gaierror as e:
if e.args[0] == socket.EAI_NONAME:
return False
raise
return True
示例4: resolve
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def resolve(self, host: str, port: int=0,
family: int=socket.AF_INET) -> List[Dict[str, Any]]:
try:
resp = await self._resolver.gethostbyname(host, family)
except aiodns.error.DNSError as exc:
msg = exc.args[1] if len(exc.args) >= 1 else "DNS lookup failed"
raise OSError(msg) from exc
hosts = []
for address in resp.addresses:
hosts.append(
{'hostname': host,
'host': address, 'port': port,
'family': family, 'proto': 0,
'flags': socket.AI_NUMERICHOST})
if not hosts:
raise OSError("DNS lookup failed")
return hosts
示例5: is_valid_address
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def is_valid_address(address):
""" check ip address, Supports IPv4 and IPv6"""
if not address or '\x00' in address:
return False
try:
res = socket.getaddrinfo(address, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror:
err = sys.exc_info()[1]
if err.args[0] == socket.EAI_NONAME:
return False
raise
return True
示例6: check_ip_addr
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def check_ip_addr(**kwargs):
""" check_ip_addr, Supports IPv4 and IPv6"""
ipaddr = kwargs["ipaddr"]
if not ipaddr or '\x00' in ipaddr:
return False
try:
res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror:
err = sys.exc_info()[1]
if err.args[0] == socket.EAI_NONAME:
return False
raise
return True
示例7: check_ip_addr
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def check_ip_addr(ipaddr):
"""check ip address, Supports IPv4 and IPv6"""
if not ipaddr or '\x00' in ipaddr:
return False
try:
res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror:
err = sys.exc_info()[1]
if err.args[0] == socket.EAI_NONAME:
return False
raise
return True
示例8: check_ip_addr
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def check_ip_addr(ipaddr):
""" check_ip_addr, Supports IPv4 and IPv6 """
if not ipaddr or '\x00' in ipaddr:
return False
try:
res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror:
err = sys.exc_info()[1]
if err.args[0] == socket.EAI_NONAME:
return False
raise
return True
示例9: check_ip_addr
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def check_ip_addr(**kwargs):
""" check_ip_addr, Supports IPv4 and IPv6 """
ipaddr = kwargs["ipaddr"]
if not ipaddr or '\x00' in ipaddr:
return False
try:
res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror:
err = sys.exc_info()[1]
if err.args[0] == socket.EAI_NONAME:
return False
raise
return True
示例10: check_ip_addr
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def check_ip_addr(ipaddr):
"""check ip address, Supports IPv4 and IPv6"""
if not ipaddr or '\x00' in ipaddr:
return False
try:
res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror:
err = sys.exc_info()[1]
if err.args[0] == socket.EAI_NONAME:
return False
raise
示例11: check_ip_addr
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def check_ip_addr(ipaddr):
""" check ip address, Supports IPv4 and IPv6 """
if not ipaddr or '\x00' in ipaddr:
return False
try:
res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror:
err = sys.exc_info()[1]
if err.args[0] == socket.EAI_NONAME:
return False
raise
return True
示例12: resolve_with_query
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def resolve_with_query(self, host, port=0, family=socket.AF_INET):
if family == socket.AF_INET6:
qtype = 'AAAA'
else:
qtype = 'A'
hosts = []
resp = yield from self._resolver.query(host, qtype)
for rr in resp:
hosts.append(
{'hostname': host,
'host': rr.host, 'port': port,
'family': family, 'proto': 0,
'flags': socket.AI_NUMERICHOST})
return hosts
示例13: resolve
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def resolve(self, host, port=0, family=socket.AF_INET):
return [
{
'hostname': host,
'host': self._LOCAL_HOST[family],
'port': self.port,
'family': family,
'proto': 0,
'flags': socket.AI_NUMERICHOST,
},
]
示例14: is_valid_ip_bysocket
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def is_valid_ip_bysocket(ip):
if not ip or '\x00' in ip:
# getaddrinfo resolves empty strings to localhost, and truncates
# on zero bytes.
return False
try:
res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror as e:
if e.args[0] == socket.EAI_NONAME:
return False
raise
示例15: is_valid_ip
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_NUMERICHOST [as 别名]
def is_valid_ip(ip):
"""Returns true if the given string is a well-formed IP address.
Supports IPv4 and IPv6.
"""
try:
res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM,
0, socket.AI_NUMERICHOST)
return bool(res)
except socket.gaierror as e:
if e.args[0] == socket.EAI_NONAME:
return False
raise
return True