File size: 1,811 Bytes
3b1664c
 
d322c3a
3b1664c
 
d322c3a
 
 
 
3b1664c
d322c3a
 
3b1664c
d322c3a
3b1664c
 
 
d322c3a
3b1664c
 
 
 
 
 
d322c3a
3b1664c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d322c3a
 
 
 
 
 
 
3b1664c
d322c3a
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pandas as pd
import random
import logging
from datetime import datetime, timedelta

# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

# Generate random timestamps within the last 90 days
def random_timestamp():
    start = datetime.now() - timedelta(days=90)
    return start + timedelta(seconds=random.randint(0, 60 * 60 * 24 * 90))

# Generate random IP addresses
def random_ip():
    return ".".join(str(random.randint(0, 255)) for _ in range(4))

# Define dataset attributes
protocols = ["TCP", "UDP", "ICMP"]
actions = ["Allow", "Deny"]
threat_levels = ["Low", "Medium", "High", "Critical"]
threat_types = ["DDoS", "Brute Force", "SQL Injection", "Port Scan", "Malware"]
response_actions = ["Blocked", "Alerted", "Monitored", "Escalated"]

# Generate dataset
data = {
    "timestamp": [random_timestamp().strftime("%Y-%m-%d %H:%M:%S") for _ in range(500)],
    "source_ip": [random_ip() for _ in range(500)],
    "destination_ip": [random_ip() for _ in range(500)],
    "protocol": [random.choice(protocols) for _ in range(500)],
    "port": [random.randint(20, 65535) for _ in range(500)],
    "action": [random.choice(actions) for _ in range(500)],
    "threat_level": [random.choice(threat_levels) for _ in range(500)],
    "threat_type": [random.choice(threat_types) for _ in range(500)],
    "response_action": [random.choice(response_actions) for _ in range(500)],
}

# Convert to DataFrame
df = pd.DataFrame(data)

# Save as CSV with validation
output_file = "nsg_dataset.csv"
try:
    df.to_csv(output_file, index=False)
    logging.info(f"✅ NSG Dataset ({len(df)} records) saved to '{output_file}' successfully!")
except Exception as e:
    logging.error(f"❌ Error saving dataset: {e}")

# Preview dataset
print(df.head())