pcap에서 csv로 변환 된 매우 큰 csv 파일로 가득 찬 디렉토리가 있습니다.pcap로 가득 찬 디렉토리에서 csv 파일로 가장 일반적인 ip 가져 오기
나는 그 디렉토리에있는 각 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()
나는 정확히 파이썬 프로 아니에요, 그래서이 작업을 수행 할 수있는 더 좋은 방법이있을 수있다, 그러나 이것은 내가 지금까지 들어 왔 것입니다.