Skip to main content

LocalPortManager 🔌

Python 3.8+ License: MIT Zero Dependencies CI Coverage PyPI Code style: black

A lightweight, zero-dependency local reverse proxy for managing multiple services on dynamic ports. Perfect for development environments, penetration testing frameworks, and microservice development.

✨ Features

  • 🚀 Zero External Dependencies - Uses only Python standard library (3.8+)
  • 🔄 Dynamic Port Allocation - Automatically finds available ports (4000-4999)
  • 📝 Service Registry - Persistent JSON-based service mappings
  • 🌐 HTTP Reverse Proxy - Route requests by hostname
  • 🔒 Thread-Safe - Concurrent request handling
  • ⚡ Lightweight - Single file, minimal overhead

📋 Requirements

  • Python 3.8 or higher
  • *.localhost DNS resolution (default on most systems including Kali Linux)

🚀 Quick Start

1. Start the Proxy Server

python localportmanager.py proxy

The proxy starts on http://127.0.0.1:1355 by default.

2. Register a Service

# Register a simple HTTP server
python localportmanager.py register myapp "python -m http.server {port}"

# Register a custom application
python localportmanager.py register api "uvicorn main:app --port {port}"

3. Access Your Service

Once registered, access your service through the proxy:

http://myapp.localhost:1355

📖 Usage

Commands

Command Description
proxy Start the reverse proxy server
register <name> <command> Register a new service
unregister <name> Remove a service from registry
list List all registered services
status Show proxy status and services

Options

# Start proxy on custom port
python localportmanager.py --port 8080 proxy

# Use custom state file
python localportmanager.py --state-file /path/to/registry.json proxy

# Auto-start service without prompting
python localportmanager.py register myapp "cmd" --yes

🔧 Examples

Web Development

# Register multiple frontend applications
python localportmanager.py register frontend-react "npm run dev -- --port {port}"
python localportmanager.py register frontend-vue "npm run serve -- --port {port}"
python localportmanager.py register api "python -m uvicorn api:app --port {port}"

Access via:

  • http://frontend-react.localhost:1355
  • http://frontend-vue.localhost:1355
  • http://api.localhost:1355

Penetration Testing (Zen-AI-Pentest)

# Register various listeners
python localportmanager.py register listener-01 "nc -lvp {port}"
python localportmanager.py register payload-server "python -m http.server {port}"
python localportmanager.py register api-server "python api.py {port}"

Docker Integration

# Register Docker container ports
python localportmanager.py register grafana "docker run -p {port}:3000 grafana/grafana"

🏗️ Architecture

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│   Client        │────▶│  LocalPortManager │────▶│  Backend Service │
│                 │     │  Proxy (127.0.0.1:1355)  │                 │
└─────────────────┘     └──────────────────┘     └─────────────────┘
                              │                           │
                              ▼                           ▼
                        ┌─────────────┐             ┌─────────────┐
                        │   Registry  │             │  Dynamic    │
                        │  (JSON)     │             │  Port (4000+)│
                        └─────────────┘             └─────────────┘

🔌 Service Routing

LocalPortManager routes requests based on the Host header:

Host Header Routes To
myapp.localhost:1355 Service "myapp"
myapp Service "myapp"
127.0.0.1:1355/myapp/... Service "myapp" (path-based fallback)

📁 Project Structure

.
├── localportmanager.py    # Main application (single file)
├── README.md              # This file
├── LICENSE                # MIT License
└── examples/              # Usage examples

🛠️ Development

Running Tests

# Test the module
python -c "import localportmanager; print('OK')"

# Test with verbose output
python localportmanager.py --version

Code Structure

  • PortRegistry - Manages service/port mappings
  • ReverseProxyHandler - HTTP request handler
  • LocalPortManager - Main application class

⚠️ Security Notes

  • Proxy only binds to 127.0.0.1 (localhost)
  • No authentication by design (local development tool)
  • State file stored in /tmp by default (cleared on reboot)
  • For production use, consider adding authentication layer

🤝 Integration with Zen-AI-Pentest

LocalPortManager is designed to work seamlessly with Zen-AI-Pentest:

# Inside Zen-AI-Pentest agent
from localportmanager import LocalPortManager

lpm = LocalPortManager(proxy_port=1355)
port = lpm.register_service("exploit-listener", "nc -lvp {port}")
print(f"Listener accessible at: http://exploit-listener.localhost:1355")

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Inspired by the need for simple service management in penetration testing
  • Built for the Zen-AI-Pentest framework
  • Zero-dependency philosophy for maximum portability

📞 Support


Made with ❤️ for the cybersecurity community

Metadata

Release files for localportmanager 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for localportmanager 1.0.3
File Size Uploaded
localportmanager-1.0.3.tar.gz 17.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for localportmanager 1.0.3
File Interpreter ABI Platform
localportmanager-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 26.0 kB

Release files / localportmanager-1.0.3.tar.gz

Download URL localportmanager-1.0.3.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
14424890a64408f50630349b3badb1b4e0462e20dc44b513c3be87391203caa9
BLAKE2b-256 checksum
How to use checksums
111731de6e56858c69113d09531ac948c39971cc8c81575d883c92f7dc0504fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / localportmanager-1.0.3-py3-none-any.whl

Download URL localportmanager-1.0.3-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ef42af47a5e357331ae1522aca22946e2f4e8b5112af00c54a6faa2e20293d7
BLAKE2b-256 checksum
How to use checksums
03f4bbd6502f846e4f2768035606e5dc85206c547f538baa6d39af635f71716e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page