首先,我在网上和 stackoverflow 上搜索了大约 3 天,但没有找到我一直在寻找的任何东西。
我正在进行每周一次的安全审计,我会在其中取回一个带有 IP 和开放端口的 .csv 文件。它们看起来像这样:
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
不同的是: 10.12.7.8 :23关闭了。 10.24.0.2:22和10.75.1.0:23 已打开。
我想要一个打印出来的脚本:
[-] 10.12.7.8:23
[+] 10.24.0.2:22
[+] 10.75.1.0:23
我怎样才能制作这样的脚本?我尝试了我的 difflib,但这不是我需要的。我还需要能够稍后将其写入文件或将该输出作为我已经有脚本的邮件发送。
我不能使用 Unix,因为我们公司有 Windows 环境,不允许使用其他操作系统。所以我不能使用diff
或其他一些很棒的工具。
这是我的第一次尝试:
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()
这是我的第二次尝试
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()