Test network security controls against known malicious IP addresses from multiple threat intelligence feeds
The known_IP() function tests your network’s ability to detect and block connections to known malicious IP addresses. It downloads threat intelligence from multiple reputable sources and attempts socket connections to validate your security controls.
Randomly selects 5 IPs from each feed (15 total samples) and validates them using IP address pattern matching.
for file in saved_files: with open(file, 'r') as f: lines = f.readlines() for _ in range(5): randomIP = random.choice(lines) if check_ip(randomIP): sampleIP.append(randomIP)
3
Port Scanning
Tests socket connections to each IP on common service ports (80, 22, 443) with a 5-second timeout.
ports = [80, 22, 443]for ip in sampleIP: for port in ports: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) result = sock.connect_ex((ip, port))
4
Results Logging
Logs all connection attempts with timestamps to IP_Results.txt, marking each as SUCCESSFUL or FAILED.
5
Cleanup
Removes temporary downloaded feed files after testing completes.
Your firewall should block all connection attempts to these IPs. Check firewall logs for denied connections.
IDS/IPS Alerts
Intrusion detection systems should generate alerts when connections are attempted to known malicious IPs.
Network Logs
Review network traffic logs to ensure outbound connections to malicious IPs are logged and prevented.
SIEM Events
Security information and event management systems should correlate these IPs with threat intelligence feeds.
If connections are SUCCESSFUL, this indicates your security controls may not be blocking known malicious IPs. Review your firewall rules and threat intelligence integrations.
# Run Somnium and select option 1python main.py# Choose: #1 Test connection with known bad IPs# Review resultscat IP_Results.txt
The test generates 45 total connection attempts (15 IPs × 3 ports). Each attempt has a 5-second timeout, so the test takes approximately 3-4 minutes to complete.