1. _vios
  2. PcapAnalyzeTest

Commits

mori:home  committed 60e0bca

分割時間をファイルに出力.ポートごと通信量合算出力

  • Participants
  • Parent commits 4793da3
  • Branches master

Comments (0)

Files changed (3)

File .gitignore

View file
 *.pyc
 tmp
 *.pcap
+*.tcp.txt
+*.udp.txt

File main.py

View file
 import os
 import shutil
 
-kSliceSec = 3600
+kSummaryFileName = "summary.txt"
+kSliceSec = 60
 
 pcapFiles = glob.glob("*.pcap")
 if len(pcapFiles) != 1:
 os.mkdir("tmp")
 os.system("editcap -i %d %s %s" % (
     kSliceSec,pcapFiles[0],"tmp/sliced.pcap"))
-
+w = open("tmp\\%s" % kSummaryFileName,"w")
+w.write("SliceSec,%d"% kSliceSec)
+w.close()

File statistics.py

View file
 pcapList = glob.glob("tmp/*.pcap")
 loopCount = 0
 
+sumTcpPortDict = dict()
+sumUdpPortDict = dict()
+
 for pcapFile in pcapList:
     tcpPortDict = dict()
     udpPortDict = dict()
         udpPortDict.setdefault(int(port),0)
         udpPortDict[int(port)] += 1
 
-    w = open("%d.tcp.txt" % loopCount,"w")
+    w = open("tmp\\%d.tcp.txt" % loopCount,"w")
     for key,value in tcpPortDict.iteritems():
+        sumTcpPortDict.setdefault(key,0)
+        sumTcpPortDict[key] += value
         w.write("%d,%d\n" % (key,value))
     w.close()
 
-    w = open("%d.udp.txt" % loopCount,"w")
+    w = open("tmp\\%d.udp.txt" % loopCount,"w")
     for key,value in udpPortDict.iteritems():
+        sumUdpPortDict.setdefault(key,0)
+        sumUdpPortDict[key] += value
         w.write("%d,%d\n" % (key,value))
     w.close()
     loopCount += 1
 
 
+w = open("tmp\\tcp.txt","w")
+for key,value in sumTcpPortDict.iteritems():
+    w.write("%d,%d\n" % (key,value))
+w.close()
+
+w = open("tmp\\udp.txt","w")
+for key,value in sumUdpPortDict.iteritems():
+    w.write("%d,%d\n" % (key,value))
+w.close()