Make a function that reads a text file containing a list of IP addresses and generates two other files, one containing valid IP addresses and one containing
the invalid addresses. The format of an IP address is num1.num.num.num
, where num1
goes from 1 to 255 and num
goes from 0 to 255.
def ips(arq1):
ipsv=open('ipsv.txt','w')
ipsi=open('ipsi.txt','w')
c=0
junta=""
for ip in arq1:
listaip = []
for i in range(len(ip)):
if ip[i]!=".":
junta=junta+ip[i]
junta=(junta)
if len(junta)==3:
listaip.append(int(junta.strip()))
junta=""
else:
continue
print(listaip)
for x in listaip:
if listaip[0]>=1 and listaip[0]<=255 and x>=0 and x<=255:
ipsv.write(str(x))
else:
ipsi.write(str(x))
ipsi.close()
ipsv.close()
arq1=open('ips.txt','r')
ips(arq1)