这是我当前的代码:
fd = open('/var/log/secure.log')
syslog = fd.readlines()
countTable = {} # initialization of a dictionary
for line in syslog:
data = line.split()
if len(data) >= 15:
if data[14] in ['user=root']:
intrusions = []
ip = data[13].replace('rhost=', "")
intrusions.extend(ip)
print "intruder:", intrusions
这是我得到的输出:
intruder: ['218.92.0.201']
intruder: ['222.186.173.142']
intruder: ['222.186.173.142']
intruder: ['222.186.173.142']
intruder: ['218.92.0.201']
intruder: ['218.92.0.201']
intruder: ['222.186.30.218']
intruder: ['218.92.0.201']
我如何将所有这些IP放入相同的“入侵”列表?
谢谢!
您只需要在第一个循环之前移动intrusions = []
:
countTable = {} # initialization of a dictionary
intrusions = []
for line in syslog:
data = line.split()
if len(data) >= 15:
if data[14] in ['user=root']:
ip = data[13].replace('rhost=', "")
intrusions.extend(ip)
print "intruder:", intrusions