LAN device discovery and TCP port scanning
pip install philiprehberger-net-scannerLAN device discovery and TCP port scanning.
pip install philiprehberger-net-scanner
from philiprehberger_net_scanner import scan_network
devices = scan_network("192.168.1.0/24", timeout=2.0)
for device in devices:
print(f"{device.ip} - {device.hostname or 'unknown'} ({device.response_time_ms:.1f}ms)")
from philiprehberger_net_scanner import scan_ports
# Scan common ports
ports = scan_ports("192.168.1.1", ports="common")
for port in ports:
print(f"Port {port.number}: {port.state} ({port.service})")
# Scan specific range
ports = scan_ports("192.168.1.1", ports=range(1, 1024), timeout=0.5)
# Scan specific ports
ports = scan_ports("192.168.1.1", ports=[22, 80, 443, 3306, 5432])
from philiprehberger_net_scanner import is_port_open
if is_port_open("example.com", 443, timeout=1.0):
print("HTTPS is reachable")
import asyncio
from philiprehberger_net_scanner import async_scan_ports
ports = asyncio.run(async_scan_ports("192.168.1.1", ports=range(1, 65536), timeout=0.5))
| Function / Class | Description |
|---|---|
scan_network(cidr, timeout=1.0, max_workers=64, resolve_hostnames=True) | Discover devices on a network using TCP connect probes |
scan_ports(host, ports="common", timeout=1.0, max_workers=128) | Scan TCP ports on a host ("common", range, or list[int]) |
async_scan_ports(host, ports="common", timeout=1.0, concurrency=128) | Asyncio-based version of scan_ports |
is_port_open(host, port, timeout=1.0) | One-off boolean check for a single TCP port |
Device | Discovered host: ip, hostname, mac, response_time_ms |
PortResult | Scan result: number, state ("open"/"closed"/"filtered"), service |
pip install -e .
python -m pytest tests/ -v
If you find this project useful: