-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase.py
More file actions
28 lines (24 loc) · 818 Bytes
/
Copy pathdatabase.py
File metadata and controls
28 lines (24 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sqlite3
class NetworkDatabase:
def __init__(self, db_name='network_traffic.db'):
self.conn = sqlite3.connect(db_name)
self.cursor = self.conn.cursor()
self.create_table()
def create_table(self):
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS captured_traffic (
src_ip TEXT,
dst_ip TEXT,
protocol TEXT,
port INTEGER
)
''')
self.conn.commit()
def insert_data(self, src_ip, dst_ip, protocol, port):
self.cursor.execute('''
INSERT INTO captured_traffic (src_ip, dst_ip, protocol, port)
VALUES (?, ?, ?, ?)
''', (src_ip, dst_ip, protocol, port))
self.conn.commit()
def close(self):
self.conn.close()