Adding infos related to the capture in the generated report
This commit is contained in:
parent
68bcf39451
commit
f465d46d92
@ -20,7 +20,8 @@ class Report(object):
|
||||
capture_directory, "assets/conns.json"))
|
||||
self.device = self.read_json(os.path.join(
|
||||
capture_directory, "assets/device.json"))
|
||||
|
||||
self.capinfos = self.read_json(os.path.join(
|
||||
capture_directory, "assets/capinfos.json"))
|
||||
try:
|
||||
with open(os.path.join(self.capture_directory, "capture.pcap"), "rb") as f:
|
||||
self.capture_sha1 = hashlib.sha1(f.read()).hexdigest()
|
||||
@ -184,7 +185,10 @@ class Report(object):
|
||||
self.device["mac_address"])
|
||||
header += "Report generated on {}<br />".format(
|
||||
datetime.now().strftime("%d/%m/%Y at %H:%M:%S"))
|
||||
|
||||
header += "Capture duration: {}<br />".format(
|
||||
self.capinfos["Capture duration"])
|
||||
header += "Number of packets: {}<br />".format(
|
||||
self.capinfos["Number of packets"])
|
||||
header += "Capture SHA1: {}<br />".format(self.capture_sha1)
|
||||
header += "</p>"
|
||||
header += "</div>"
|
||||
|
@ -7,6 +7,7 @@ from os import mkdir, path
|
||||
from flask import send_file, jsonify
|
||||
import datetime
|
||||
import shutil
|
||||
import json
|
||||
import random
|
||||
import sys
|
||||
import re
|
||||
@ -15,9 +16,6 @@ import re
|
||||
class Capture(object):
|
||||
|
||||
def __init__(self):
|
||||
self.capture_dir = False
|
||||
self.assets_dir = False
|
||||
self.capture_token = False
|
||||
self.random_choice_alphabet = "ABCDEF1234567890"
|
||||
|
||||
def start_capture(self):
|
||||
@ -98,14 +96,33 @@ class Capture(object):
|
||||
|
||||
def stop_capture(self):
|
||||
"""
|
||||
Stoping tshark if any instance present.
|
||||
Stop tshark if any instance present & ask create_capinfos.
|
||||
:return: dict as a small confirmation.
|
||||
"""
|
||||
|
||||
# Kill instance of tshark if any.
|
||||
if terminate_process("tshark"):
|
||||
self.create_capinfos()
|
||||
return {"status": True,
|
||||
"message": "Capture stopped"}
|
||||
else:
|
||||
return {"status": False,
|
||||
"message": "No active capture"}
|
||||
|
||||
def create_capinfos(self):
|
||||
"""
|
||||
Creates a capinfo json file.
|
||||
:return: dict as a small confirmation.
|
||||
"""
|
||||
infos = sp.Popen(["capinfos", self.pcap],
|
||||
stdout=sp.PIPE, stderr=sp.PIPE)
|
||||
infos = infos.communicate()[0]
|
||||
data = {}
|
||||
for l in infos.decode().splitlines():
|
||||
try:
|
||||
l = l.split(": ") if ": " in l else l.split("= ")
|
||||
if len(l[0]) and len(l[1]):
|
||||
data[l[0].strip()] = l[1].strip()
|
||||
except:
|
||||
continue
|
||||
with open("{}capinfos.json".format(self.assets_dir), 'w') as f:
|
||||
json.dump(data, f)
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user