我编写了以下代码以从文件中获取所有IP地址并将其打印出来:
with open("C:\\users\\joey\\desktop\\access.log",'r') as bestand:
for line in bestand:
try:
splittedline = line.split('sftp-session')[1].split("[")[1].split("]")[0]
except Exception:
continue
print splittedline
以下代码打印另一个文件的所有IP地址:
^{pr2}$如何比较这两个文件,只显示唯一的IP地址和删除重复?在
输出atm如下:
217.172.190.19
217.210.165.43
218.250.241.229
223.18.115.229
223.133.243.101
如果顺序不重要,请使用集合:
然后,您可以使用set方法查看两个文件中的IP地址,这些IP地址只在一个文件中,或者获取所有唯一的IP地址:
两个文件中都有哪些IP?在
^{pr2}$哪些IP只在文件1中?在
所有唯一IP:
相关问题 更多 >
编程相关推荐