Update dataset
Browse files
dataset
CHANGED
|
@@ -1,24 +1,28 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import random
|
|
|
|
| 3 |
from datetime import datetime, timedelta
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
| 6 |
def random_timestamp():
|
| 7 |
-
start = datetime(
|
| 8 |
-
return start + timedelta(seconds=random.randint(0, 60 * 60 * 24 *
|
| 9 |
|
| 10 |
-
# Generate random
|
| 11 |
def random_ip():
|
| 12 |
return ".".join(str(random.randint(0, 255)) for _ in range(4))
|
| 13 |
|
| 14 |
-
#
|
| 15 |
protocols = ["TCP", "UDP", "ICMP"]
|
| 16 |
actions = ["Allow", "Deny"]
|
| 17 |
threat_levels = ["Low", "Medium", "High", "Critical"]
|
| 18 |
threat_types = ["DDoS", "Brute Force", "SQL Injection", "Port Scan", "Malware"]
|
| 19 |
response_actions = ["Blocked", "Alerted", "Monitored", "Escalated"]
|
| 20 |
|
| 21 |
-
#
|
| 22 |
data = {
|
| 23 |
"timestamp": [random_timestamp().strftime("%Y-%m-%d %H:%M:%S") for _ in range(500)],
|
| 24 |
"source_ip": [random_ip() for _ in range(500)],
|
|
@@ -34,7 +38,13 @@ data = {
|
|
| 34 |
# Convert to DataFrame
|
| 35 |
df = pd.DataFrame(data)
|
| 36 |
|
| 37 |
-
# Save as CSV
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import random
|
| 3 |
+
import logging
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
|
| 6 |
+
# Configure logging
|
| 7 |
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 8 |
+
|
| 9 |
+
# Generate random timestamps within the last 90 days
|
| 10 |
def random_timestamp():
|
| 11 |
+
start = datetime.now() - timedelta(days=90)
|
| 12 |
+
return start + timedelta(seconds=random.randint(0, 60 * 60 * 24 * 90))
|
| 13 |
|
| 14 |
+
# Generate random IP addresses
|
| 15 |
def random_ip():
|
| 16 |
return ".".join(str(random.randint(0, 255)) for _ in range(4))
|
| 17 |
|
| 18 |
+
# Define dataset attributes
|
| 19 |
protocols = ["TCP", "UDP", "ICMP"]
|
| 20 |
actions = ["Allow", "Deny"]
|
| 21 |
threat_levels = ["Low", "Medium", "High", "Critical"]
|
| 22 |
threat_types = ["DDoS", "Brute Force", "SQL Injection", "Port Scan", "Malware"]
|
| 23 |
response_actions = ["Blocked", "Alerted", "Monitored", "Escalated"]
|
| 24 |
|
| 25 |
+
# Generate dataset
|
| 26 |
data = {
|
| 27 |
"timestamp": [random_timestamp().strftime("%Y-%m-%d %H:%M:%S") for _ in range(500)],
|
| 28 |
"source_ip": [random_ip() for _ in range(500)],
|
|
|
|
| 38 |
# Convert to DataFrame
|
| 39 |
df = pd.DataFrame(data)
|
| 40 |
|
| 41 |
+
# Save as CSV with validation
|
| 42 |
+
output_file = "nsg_dataset.csv"
|
| 43 |
+
try:
|
| 44 |
+
df.to_csv(output_file, index=False)
|
| 45 |
+
logging.info(f"✅ NSG Dataset ({len(df)} records) saved to '{output_file}' successfully!")
|
| 46 |
+
except Exception as e:
|
| 47 |
+
logging.error(f"❌ Error saving dataset: {e}")
|
| 48 |
|
| 49 |
+
# Preview dataset
|
| 50 |
+
print(df.head())
|