First of all, i searched on the web and stackoverflow for around 3 days and haven't found anything i've been looking for.
I am doing a weekly security audit where i get back a .csv file with the IPs and the open ports. They look like this:
20160929.csv
10.4.0.23;22
10.12.7.8;23
10.18.3.192;23
20161006.csv
10.4.0.23;22
10.18.3.192;23
10.24.0.2;22
10.75.1.0;23
The difference is: 10.12.7.8:23 got closed. 10.24.0.2:22 and 10.75.1.0:23 got opened.
I want a script which prints me out:
[-] 10.12.7.8:23
[+] 10.24.0.2:22
[+] 10.75.1.0:23
How can i make a script like this? I tried my difflib but that isn't what i need. I need to be able to also write that to files later or send that output as a mail which i have a script for already.
I can't use Unix, because in our company we have a Windows environment and are not allowed to use another OS. So i can't use diff
or some other great tools.
This is my first attempt:
old = set((line.strip() for line in open('1.txt', 'r+')))
new = open('2.txt', 'r+')
diff = open('diff.txt', 'w')
for line in new:
if line.strip() not in old:
diff.write(line)
new.close()
diff.close()
This is my second attempt
old = set((line.strip() for line in open('1.txt', 'r+')))
new = open('2.txt', 'r+')
diff = open('diff.txt', 'w')
for line in new:
if line.strip() not in old:
diff.write(line)
new.close()
diff.close()