|
import pandas as pd |
|
import random |
|
import logging |
|
from datetime import datetime, timedelta |
|
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") |
|
|
|
|
|
def random_timestamp(): |
|
start = datetime.now() - timedelta(days=90) |
|
return start + timedelta(seconds=random.randint(0, 60 * 60 * 24 * 90)) |
|
|
|
|
|
def random_ip(): |
|
return ".".join(str(random.randint(0, 255)) for _ in range(4)) |
|
|
|
|
|
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"] |
|
|
|
|
|
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)], |
|
} |
|
|
|
|
|
df = pd.DataFrame(data) |
|
|
|
|
|
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}") |
|
|
|
|
|
print(df.head()) |
|
|