import socket
def is_valid_ipv4_address(address):
try:
addr= socket.inet_pton(socket.AF_INET, address)
except AttributeError: # no inet_pton here, sorry
try:
addr= socket.inet_aton(address)
except socket.error:
return False
return address.count('.') == 3
except socket.error: # not a valid address
return False
return True
def is_valid_ipv6_address(address):
try:
addr= socket.inet_pton(socket.AF_INET6, address)
except socket.error: # not a valid address
return False
return True
阅读(2428) | 评论(0) | 转发(0) |