I am a complete noob and have google made my first python script.
I am opening a 2 files and removing list 1 from list2.
Once list2 has been modified to remove what was in list 1, I want to sort the list by IP network. for example:
1.1.1.1/24
1.1.1.1/32
5.5.5.5/20
10.10.11.12/26
10.11.10.4/32
currently it is sorting
1.1.1.1/24
1.1.1.1/32
10.10.11.12/26
10.11.10.4/32
5.5.5.5/20
code:
import os
import sys
import random
import re
text_file = open("D:/file/update2.txt", "rt")
lines = str(text_file.readlines())
text_file.close()
ip_address = r'(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]
{1,3}/\d{1,2})'
foundip = re.findall( ip_address, lines )
text_file2 = open("D:/file/Block.txt", "rt")
lines2 = str(text_file2.readlines())
text_file2.close()
foundip2 = re.findall( ip_address, lines2 )
test =(list(set(foundip2) - set(foundip)))
items = sorted(test)
print (*items, sep = "\n")
Thanks in advance.