Commit 4898ba76 authored by Imesh Dilshan's avatar Imesh Dilshan

backend started

parents
Pipeline #6674 failed with stages
from flask import Flask, request, jsonify
import pyshark
import pydot
app = Flask(_name_)
@app.route('/generate_event_flow_graph', methods=['POST'])
def generate_event_flow_graph():
# Get the uploaded pcap file from the request
pcap_file = request.files['pcap_file']
# Specify the output file path and name
output_file = 'event_flow_graph.png'
try:
# Save the uploaded file
pcap_file.save('upload.pcap')
# Read the pcap file
pcap = pyshark.FileCapture('upload.pcap')
# Create a set to store unique IP addresses
ip_addresses = set()
# Iterate over the packets in the pcap file
for packet in pcap:
# Check if the packet has an IP layer
if 'IP' in packet:
ip_layer = packet['IP']
# Add the source and destination IP addresses to the set
ip_addresses.add(ip_layer.src)
ip_addresses.add(ip_layer.dst)
# Create a graph of the events
graph = pydot.Dot()
# Add a node for each IP address
for ip_address in ip_addresses:
graph.add_node(pydot.Node(ip_address, label=ip_address))
# Add an edge for each communication between two IP addresses
for packet in pcap:
if 'IP' in packet:
ip_layer = packet['IP']
graph.add_edge(pydot.Edge(ip_layer.src, ip_layer.dst))
# Save the graph to a file
graph.write_png(output_file)
# Return the file path for the generated graph
return jsonify({'graph_url': output_file})
except Exception as e:
return jsonify({'error': str(e)}), 500
if _name_ == '_main_':
app.run()
\ No newline at end of file
aniso8601==8.0.0
click==7.1.2
Flask==1.1.2
Flask-RESTful==0.3.8
Flask-SQLAlchemy==2.4.3
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
pytz==2020.1
six==1.15.0
SQLAlchemy==1.3.18
Werkzeug==1.0.1
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment