3. Validar dirección IP¶
Data file:
IPS.txt
200.135.80.9 192.168.1.1 8.35.67.74 257.32.4.5 85.345.1.2 1.2.3.4 9.8.284.5 192.168.0.256
xxxxxxxxxx
def ip_ok(ip):
ip = ip.split(".")
for byte in ip:
if int(byte) > 255:
return False
return True
ips = open("IPS.txt")
validos = open("Validos.txt", "w")
invalidos = open("Invalidos.txt", "w")
for linea in ips.readlines():
if ip_ok(linea):
validos.write(linea)
else:
invalidos.write(linea)
ips.close()
validos.close()
invalidos.close()
Activity: 3.2 ActiveCode (ac_l23_3)
Data file:
Validos.txt
Data file:
Invalidos.txt
You have attempted 1 of 3 activities on this page