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
5533b36d
Commit
5533b36d
authored
Sep 06, 2023
by
Gamage G.G.I.V.M
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
d2854a7d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
0 deletions
+89
-0
IT20094690/store.py
IT20094690/store.py
+89
-0
No files found.
IT20094690/store.py
0 → 100644
View file @
5533b36d
import
subprocess
import
pyshark
import
sqlite3
def
open_ryu_controller
():
try
:
subprocess
.
Popen
([
"ryu-manager"
,
"ryu.app.simple_switch_13"
])
except
FileNotFoundError
:
print
(
"Ryu controller not found. Please make sure Ryu is installed and in your system's PATH."
)
def
capture_packets
(
interface
,
connection
,
cursor
):
capture
=
pyshark
.
LiveCapture
(
interface
=
interface
)
try
:
# Start capturing packets
for
packet
in
capture
.
sniff_continuously
():
# Process and analyze the packet
process_packet
(
packet
,
connection
,
cursor
)
except
KeyboardInterrupt
:
# Handle keyboard interrupt (e.g., when the user presses Ctrl+C)
pass
def
process_packet
(
packet
,
connection
,
cursor
):
# Extract relevant information from the packet
# Check the protocol and access the appropriate attributes for source and destination addresses
if
'IP'
in
packet
:
source
=
packet
[
'IP'
]
.
src
destination
=
packet
[
'IP'
]
.
dst
elif
'IPv6'
in
packet
:
source
=
packet
[
'IPv6'
]
.
src
destination
=
packet
[
'IPv6'
]
.
dst
else
:
source
=
'Unknown'
destination
=
'Unknown'
# Other attributes
protocol
=
packet
.
highest_layer
length
=
packet
.
length
# Perform vulnerability scanning or analysis on the packet
# You can add your custom logic here to detect vulnerabilities
# Print packet details
print
(
f
"Protocol: {protocol}, Source: {source}, Destination: {destination}, Length: {length}"
)
# Insert packet data into the database table
insert_packet_data
(
connection
,
cursor
,
protocol
,
source
,
destination
,
length
)
def
create_packet_table
(
cursor
):
# Create the packet table if it doesn't exist
cursor
.
execute
(
'''
CREATE TABLE IF NOT EXISTS packets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
protocol TEXT,
source TEXT,
destination TEXT,
length INTEGER
)
'''
)
def
insert_packet_data
(
connection
,
cursor
,
protocol
,
source
,
destination
,
length
):
# Insert packet data into the database table
cursor
.
execute
(
'''
INSERT INTO packets (protocol, source, destination, length)
VALUES (?, ?, ?, ?)
'''
,
(
protocol
,
source
,
destination
,
length
))
connection
.
commit
()
if
__name__
==
'__main__'
:
# Specify the interface to capture packets on (e.g., 'eth0' or 'en0')
interface
=
'ens33'
# Create a connection to the SQLite database file
connection
=
sqlite3
.
connect
(
'captured_packets.db'
)
cursor
=
connection
.
cursor
()
# Call the function to create the packet table
create_packet_table
(
cursor
)
# Call the function to start the Ryu controller
open_ryu_controller
()
# Call the function to start capturing packets
capture_packets
(
interface
,
connection
,
cursor
)
# Close the database connection when done
connection
.
close
()
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