Command-line Python reconnaissance tool recon.py that probes targets, enumerates services and HTTP apps, inspects TLS, fingerprints web stacks, and emits machine-readable reports.
This tool performs a TCP connect scan against one or more hosts and a configurable set of ports. For each open port it optionally grabs service banners, probes HTTP and HTTPS services, and analyses TLS certificates to provide a more information about exposed services. It is intended for use in controlled environments such as labs or with explicit permission on target systems. The scanner outputs a human‑readable summary to the terminal and also writes structured JSON and CSV files for later analysis, scripting, or importing into other tools.
- Python 3.10+ (uses modern type hints such as
str | None) - Network access to the target hosts and ports
- A Unix‑like environment (Linux/macOS) is recommended for easiest CLI usage
Install from requirements.txt:
requests>2.32.5
cryptography>46.0.3Create a virtual environment and install:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt--targets should point to a text file with one hostname or IP address per line, for example:
192.168.1.10
192.168.1.11
example.com
nmap.scanme.orgEmpty lines and lines starting with # are ignored.
Example command:
python3 recon.py \
--targets targets.txt \
--ports 80,443,8000-8010 \
--workers 50 \
--http \
--tls \
--output lab1 \
--timeout 3-
--targets PATH
Path to a file containing one host/IP per line (required). -
--ports SPEC
Ports to scan (required). Supported formats:- Single port:
80 - Comma‑separated:
80,443,8000 - Ranges:
1-1024 - Mixed:
80,443,8000-8010
- Single port:
-
--timeout SECONDS
Connection timeout in seconds (default:2.0). -
--workers N
Maximum number of concurrent worker threads (default:20). -
--http
Enable HTTP(S) probing and web fingerprinting on discovered open ports or ports that look like HTTP. -
--tls
Enable TLS certificate retrieval and analysis on ports that likely speak TLS (e.g. 443, 8443, 9443 or TLS‑looking banners). -
--output PREFIX
Path prefix for results. Writes:PREFIX.results.jsonPREFIX.results.csv
-
--retry N
Retries per host:port on unexpected errors (default:1), with simple backoff between attempts. -
--resume
Resume from an existingPREFIX.results.jsonif present. Only missing host:port combinations will be scanned. -
-v,--verbose
Enable verbose debug logging to stderr.
-
Console summary:
A simple overview of open, closed, and filtered ports per host. -
JSON:
PREFIX.results.json
Contains:metablock with run metadata and CLI argumentstargets[host].ports[port]with:- Port status (
open,closed,filtered,error) - Banner
- HTTP block (status, headers, methods, favicon hash, fingerprint)
- TLS block (subject, issuer, SAN, validity, key type/size, weak params)
- Fingerprint tags and timestamps
- Port status (
-
CSV:
PREFIX.results.csv
One row per open host:port with columns:hostportopenstatus_codetitleserver_headercert_subject_cncert_notAfterbanner_snippetfingerprint_tagshttp_methods_allowedhttp_methods_unsafe
- Multi‑host, multi‑port TCP connect scanning using
socketand a thread pool. - Classifies each port as:
open(connect success)closed(connect refused/error)filtered(timeout)
- Optional retries per host:port with simple exponential backoff.
- For each open TCP port, the scanner:
- Opens a TCP connection and attempts to read up to 4096 bytes.
- Tries to decode the banner as text; if that fails, stores base64‑encoded data instead.
- Banners are stored per port and a short prefix is used in CSV output.
For ports that look like HTTP or when --http is enabled:
- Tries
http://host:portand (where appropriate)https://host:port. - Follows redirects and records:
- Final URL
- HTTP status code
ServerandSet-Cookieheaders- Page
<title>and<meta name="description"> - First 4 KiB of the HTML body as a sample
Basic fingerprinting includes:
-
CMS detection
- WordPress: body markers and common paths such as
/wp-login.phpand/xmlrpc.php - Drupal: presence of
drupal.settings - Joomla: characteristic meta tag
- WordPress: body markers and common paths such as
-
Framework hints
- From
X-Powered-By, e.g. PHP, ASP.NET, Express, Django.
- From
-
WAF hints
- Headers such as Sucuri, Cloudflare, ModSecurity.
-
Auxiliary endpoints
- Checks for
robots.txtandsitemap.xmland records basic status. - Fetches
/favicon.ico, stores a SHA‑256 hash for potential favicon‑based fingerprinting.
- Checks for
- Sends an
OPTIONSrequest and parses theAllowheader if present. - If
Allowis missing, tests common methods (GET,POST,PUT,DELETE,PATCH) and considers 2xx/3xx as “allowed”. - Identifies "unsafe" methods (currently
PUT,DELETE,PATCH) to highlight potentially risky write operations.
For likely TLS ports or TLS‑looking banners:
-
Performs a TLS handshake using system CAs (verification enabled, but hostname checking disabled to support “host:port” scans).
-
Extracts:
- Subject CN
- Issuer CN
- Subject Alternative Name (SAN) DNS entries
- Validity window (
not_before,not_after) and anexpiredboolean - Public key type (e.g. RSA, ECDSA) and key size
- Signature hash algorithm
-
Flags weak parameters, such as:
- RSA keys smaller than 2048 bits
- EC curves considered weaker than
secp256r1/prime256v1 - MD5‑based signature algorithms
- All HTTP and TLS operations share a global rate limiter (
MAX_REQUESTS_PER_SECOND). - A lock and monotonic timestamps enforce a minimum delay between outbound HTTP/TLS requests across threads.
- This helps avoid flooding targets when scanning with many workers.
- When
--resumeis used with--output PREFIX, the tool:- Reads
PREFIX.results.jsonif it exists. - Skips host:port combinations that already have results.
- Appends new results and writes an updated JSON/CSV.
- Reads
This project was more complex than a simple port scanner because it combines several parts into one CLI tool: TCP checks, multi‑threading, HTTP(S) analysis, and TLS certificate parsing. Making them all work together reliably meant carefully handling timeouts, errors, and shared state like the rate limiter and logging.
What went well / key learnings:
- Turning raw socket data into simple JSON/CSV output went well.
- Using
cryptographyto read TLS certs and understand their key details. - Creating CLI flags that enable or disable features(HTTP,TLS, plain TCP) without making the tool hard and confusing to use
What was challenging:
- Making the scan handle slow or broken services without getting stuck.
- Cleaning up HTTP data (cookies, favicon hashes, methods) so it is easy to use later.
- Keeping scans fast with multiple workers while still limiting request rate to avoid sending too much traffic
Possible future improvements:
- Asynchronous (asyncio‑based) scanning instead of thread pools for better scalability.
- IPv6 support and optional UDP scanning.