def is_ipv4(value):
"""Utility function to detect if a value is a valid IPv4
:param value: The value to match against.
:return: True if the value is a valid IPv4.
"""
try:
socket.inet_pton(socket.AF_INET, value)
except AttributeError: # no inet_pton here, sorry
try:
socket.inet_aton(value)
except socket.error:
return False
return value.count('.') == 3
except socket.error: # not a valid address
return False
return True
评论列表
文章目录