0
我有一个目录充满了从pcap转换为csv的非常大的csv文件。从pcap目录中获取最常见的ip到csv文件
我想遍历该目录中的每个csv文件并获取最常见的源IP地址(第2列)。
目前我的输出是不正确的,因为它似乎已经设法让每个文件在开始之前将其值转储到下一个文件中。每个文件似乎都有相同的IP,我知道情况并非如此。
ipCounter = collections.Counter()
#iterate through all of the files in the directory, using glob
for filename in glob.glob('/path/to/directory/*'):
with open(filename) as input_file:
#skip column titles
input_file.next()
for row in csv.reader(input_file, delimiter=','):
ipCounter[row[2]] += 1
print 'Source IPs most common in: %s' % filename
print ipCounter.most_common()
我不完全亲与Python,所以有可能是一个更好的方式来做到这一点,但是这是我到目前为止得到。