๐ง AI-Cybersecurity IntegrationJuly 15, 2026โ
Tests passing
Live Threat Monitor
A lightweight CLI tool that monitors live incoming network traffic or log streams and uses AI to flag suspicious activity in real-time. Ideal for developers simulating or testing network attacks in development environments.
What It Does
- Monitors live network traffic on a specified interface.
- Uses a pre-trained AI model to detect suspicious activity.
- Logs detected threats to a JSON file (optional).
Installation
Install the required Python packages:
pip install scapy tensorflow coloramaUsage
Run the tool with the following command:
python live_threat_monitor.py --interface <network_interface> --model <path_to_model> [--log <log_file>]Arguments
--interface: The network interface to monitor (e.g.,eth0).--model: Path to the pre-trained AI model.--log: (Optional) Path to save JSON log of detected threats.
Example
sudo python live_threat_monitor.py --interface eth0 --model anomaly_model.h5 --log threats.jsonSource Code
import argparse
import json
import sys
import logging
from scapy.all import sniff, IP
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.sequence import pad_sequences
from colorama import Fore, Style
# Initialize logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
def load_ai_model(model_path):
"""Load the pre-trained anomaly detection model."""
try:
model = load_model(model_path)
logging.info("AI model loaded successfully.")
return model
except Exception as e:
logging.error(f"Failed to load AI model: {e}")
sys.exit(1)
def process_packet(packet, model, log_file):
"""Process a single packet and detect anomalies."""
if IP in packet:
packet_data = [ord(char) for char in str(packet[IP])[:100]] # Convert packet to numeric data
packet_data = pad_sequences([packet_data], maxlen=100, padding='post')
# Predict using the AI model
prediction = model.predict(packet_data, verbose=0)
if prediction[0][0] > 0.5: # Assuming 0.5 is the anomaly threshold
alert = f"{Fore.RED}[ALERT]{Style.RESET_ALL} Suspicious activity detected! Source: {packet[IP].src}, Destination: {packet[IP].dst}"
print(alert)
if log_file:
try:
with open(log_file, 'a') as log:
log_entry = {
"source": packet[IP].src,
"destination": packet[IP].dst,
"alert": "Suspicious activity detected"
}
log.write(json.dumps(log_entry) + '\n')
except Exception as e:
logging.error(f"Failed to write to log file: {e}")
def monitor_traffic(interface, model, log_file):
"""Monitor live network traffic on the specified interface."""
try:
sniff(iface=interface, prn=lambda x: process_packet(x, model, log_file), store=False)
except PermissionError:
logging.error("Permission denied. Please run the script as root or with sufficient privileges.")
sys.exit(1)
except Exception as e:
logging.error(f"Error occurred while monitoring traffic: {e}")
sys.exit(1)
def main():
parser = argparse.ArgumentParser(description="Live Threat Monitor: Monitor live network traffic for suspicious activity.")
parser.add_argument('--interface', required=True, help="Network interface to monitor (e.g., eth0)")
parser.add_argument('--model', required=True, help="Path to the pre-trained AI model")
parser.add_argument('--log', help="Optional path to save JSON log of detected threats")
args = parser.parse_args()
model = load_ai_model(args.model)
monitor_traffic(args.interface, model, args.log)
if __name__ == "__main__":
main()Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- live_threat_monitor
- Category
- AI-Cybersecurity Integration
- Generated
- July 15, 2026
- Tests
- Passing โ
- Fix Loops
- 4
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-07-15/live_threat_monitor cd generated_tools/2026-07-15/live_threat_monitor pip install -r requirements.txt 2>/dev/null || true python live_threat_monitor.py