A Python Learning Journey: From Basic Port Scanning to AI-Powered Security Automation
This project started as a simple learning exercise to explore Python's networking capabilities and quickly evolved into something much more ambitious. What began as a script to test theoretical IP generation turned into a fully-featured security audit tool with threading, API integration, CVE intelligence, and AI-powered automation.
When I first started this project, my primary question was: "Can I generate and scan theoretical IP addresses efficiently?" After proving the concept worked, I wanted to take it further. Threading allowed me to scan thousands of ports in seconds, integrating the ipinfo.io API gave me real-time geolocation data, and CVE integration transformed it into a professional threat intelligence platform.
The journey began with basic socket programming. I needed to understand how to:
The first version was straightforward but slow—scanning ports sequentially meant waiting several minutes for even a small range. That's when I discovered Python's concurrent.futures module.
Tool's command-line interface showing available options
Implementing multi-threading was a game-changer. With ThreadPoolExecutor, I could launch hundreds of connection attempts simultaneously. What previously took minutes now completed in seconds.
with concurrent.futures.ThreadPoolExecutor(max_workers=200) as executor:
futures = {executor.submit(self.scan_port, target, port): port
for port in port_range}
for future in concurrent.futures.as_completed(futures):
port, is_open, banner = future.result()
if is_open:
print(f"[+] Port {port} open - {service}")
Basic scan running on localhost (ports 1-100)
Once I had reliable port scanning working, I wanted context. An open port is just a number—what matters is where it is and what it's running. Integrating the ipinfo.io API gave me:
Extended scan (ports 1-1000) with 200 concurrent workers
The final major feature was basic vulnerability detection. By analyzing service banners and cross-referencing known dangerous configurations, the tool can flag potential security issues:
# Check for dangerous ports
if port in [23, 445, 3389]: # Telnet, SMB, RDP
vulnerabilities.append({
'port': port,
'severity': 'HIGH',
'description': f'Port {port} exposed - potentially dangerous service'
})
# Check for outdated versions
if 'openssh_4' in banner or 'openssh_5' in banner:
vulnerabilities.append({
'severity': 'MEDIUM',
'description': 'Potentially outdated SSH version detected'
})
Generated JSON report with detailed scan results
IMPORTANT: This tool is for educational purposes and authorized testing only. Scanning networks you don't own or don't have explicit permission to test is illegal and unethical.
Always test on:
Network scanning inherently produces false positives. A port might appear open due to network latency, firewall behavior, or temporary states. My solution was implementing configurable timeouts and verbose output that shows actual server responses, allowing users to verify results manually.
Admittedly, when I started this project, I was new to using classes and object-oriented design in Python. The initial code was functional but messy.
The current version uses a modular class-based architecture:
Well-organized project structure with separation of concerns
Robust error handling was essential: Network operations are unpredictable. Hosts can be unreachable, connections can timeout, APIs can be rate-limited.
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(self.timeout)
result = sock.connect_ex((ip, port))
if result == 0:
banner = sock.recv(1024).decode('utf-8', errors='ignore').strip()
return (port, True, banner)
except Exception as e:
# Silently fail and continue - network errors are expected
pass
return (port, False, "")
Testing on my local Kali Linux system revealed interesting insights:
Target: 127.0.0.1 (localhost)
Port Range: 1-1000
Scan Time: ~8 seconds
Open Ports: 1 (SSH on port 22)
Detected Service:
SSH-2.0-OpenSSH_10.0p2 Debian-8 (Current version, no vulnerabilities)
This clean result demonstrates proper system hardening—only essential services exposed, modern software versions, and minimal attack surface.
Successfully generated reports showing output capabilities
This project taught me invaluable lessons about both Python development and cybersecurity:
Version 2.0 represents a complete architectural overhaul. What started as a learning exercise evolved into a structured, modular security scanner designed for real-world workflows.
Real-time CVE enrichment showing CVSS scores and vulnerability details
This version shifted the project from "Can I scan ports?" to "Can I build a production-ready security platform?"
The newest evolution explores AI-assisted workflows and intelligent automation using OpenClaw for orchestration.
By integrating AI tooling and automation frameworks, the scanner now supports:
# AI-assisted scan with automated reporting python src/main.py 192.168.1.0/24 \ --enable-cve \ --ai-analysis \ --orchestrate \ --report-type executive # OpenClaw orchestrates: # 1. Network scanning # 2. CVE enrichment # 3. AI threat analysis # 4. Executive report generation # 5. Alert notifications
This phase focuses on learning:
It marks a shift from standalone tool → automated security workflow platform
JSON report enriched with CVE intelligence showing cve_count, CVSS scores, and vulnerability metadata
Full scan output with CVE enrichment enabled showing threat intelligence integration
Full scan output with CVE enrichment enabled showing threat intelligence integration
Security scan with CVE summary showing total CVEs, critical/high counts, and detailed vulnerability information
Enhanced command-line interface showing CVE intelligence options (--enable-cve / --no-cve)
The tool is open source and available on GitHub. Here's how to get started:
# Clone the repository git clone https://github.com/karim871/cybersecurity-audit-tool.git cd cybersecurity-audit-tool # Set up virtual environment python3 -m venv venv source venv/bin/activate # Install dependencies pip install -r requirements.txt # Run a basic scan (localhost only!) python src/main.py 127.0.0.1 -p 1-100 # Advanced scan with CVE intelligence (v2.0+) python src/main.py 127.0.0.1 -p 1-1000 -v --enable-cve -o reports/scan.json # AI-assisted scan with orchestration (v2.1+) python src/main.py 127.0.0.1 -p 1-1000 --enable-cve --ai-analysis -v
Building this tool has been an incredible learning experience. It's messy, it has limitations, and there's definitely a high likelihood of false positives—but that's okay because I know every project has room for improvement, and every security professional started somewhere.
The key takeaway isn't just the tool itself, but the journey of building it: understanding networking fundamentals, learning to handle errors, discovering the importance of clean code organization, integrating threat intelligence, and most importantly, respecting the ethical boundaries of security work.
If you're learning Python or interested in cybersecurity, I encourage you to build something similar. Start simple, iterate constantly, and don't be afraid to share messy code - that's how we all grow.
This project continues to evolve as a sandbox for learning:
Each iteration teaches something new — and that's the real purpose of the project. From basic port scanning to AI-powered security automation, the journey mirrors the evolution of modern cybersecurity practices.
Security tools are powerful and must be used responsibly. Always get explicit permission before scanning any network or system. When in doubt, test only on systems you own and control.