0

Validator IP without scripts and modules in Python. Please

14th Nov 2017, 7:47 AM
Ilya Grib
Ilya  Grib - avatar
2 Answers
+ 1
import socket def is_valid_ipv4_address(address): try: socket.inet_pton(socket.AF_INET, address) except AttributeError: # no inet_pton here, sorry try: 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: socket.inet_pton(socket.AF_INET6, address) except socket.error: # not a valid address return False return True you can do like that
14th Nov 2017, 7:53 AM
MsJ
MsJ - avatar