W sprawdzanie poprawności adresu IP Python
def validate_ip(ip_address):
octets = ip_address.split(".")
if len(octets) != 4:
# String is not an ip address if there are not 4 octets
return False
for num in octets:
if not num.isdigit():
# String is not an ip address if there are non-digits in it
return False
n = int(num)
if n < 0 or n > 255:
# String is not an ip address if an octet is less than 0 or greater than 255
return False
return True
snowy