Dec-18-2018, 08:01 AM
The script runs and process file till the end.
As you can see from the screenshot, it process 4786 rows (excluding the header)
The last ip is 158.64.55.65 on line 4668 and it's the last one in the output file. The output file is too big to upload it here (some 37 Mb), but you can see the last ip is that one
I don't see what else you expect from the script. Here it is with minimal changes
As you can see from the screenshot, it process 4786 rows (excluding the header)
The last ip is 158.64.55.65 on line 4668 and it's the last one in the output file. The output file is too big to upload it here (some 37 Mb), but you can see the last ip is that one
I don't see what else you expect from the script. Here it is with minimal changes
import ipaddress with open("fr_block.txt", "r", encoding="utf8") as fin, open("fr_block_2.txt", "w") as fout: next(fin) for i, line in enumerate(fin, start=1): line = line.split() try: net = ipaddress.IPv4Network(line[2]) except ipaddress.AddressValueError: print('{} is not valid ip'.format(line[2])) continue else: for ip_address in net: fout.write(str(ip_address) + "\n") print('\n\nTotal rows processed (excluding the header row): {}'.format(i))If I have time will add second version, e.g. I would use csv.DictReader to read the inpyt file, etc.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs