Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-261
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gamage G.G.I.V.M
2023-261
Commits
83ea025d
Commit
83ea025d
authored
May 25, 2023
by
Gamage G.G.I.V.M
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
681d2a50
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
graph.py
graph.py
+42
-0
No files found.
graph.py
0 → 100644
View file @
83ea025d
import
pyshark
import
pydot
def
generate_event_flow_graph
(
pcap_file
,
output_file
):
# Read the pcap file
pcap
=
pyshark
.
FileCapture
(
pcap_file
)
# 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
)
# Usage example
pcap_file
=
'capture.pcap'
output_file
=
'event_flow_graph.png'
generate_event_flow_graph
(
pcap_file
,
output_file
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment