def validate_ipv4(ip):
"""
Validate an ipv4 address
:param ip: The string with the ip
:return: True ip if it's valid for ipv4, False otherwise
"""
ip = str(ip)
try:
socket.inet_pton(socket.AF_INET, ip)
except AttributeError:
try:
socket.inet_aton(ip)
except socket.error:
return False
except socket.error:
return False
return True
评论列表
文章目录