Skip to main content

Zero-dependency local reverse proxy for managing services on dynamic ports

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

localportmanager-1.0.3.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

localportmanager-1.0.3-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file localportmanager-1.0.3.tar.gz.

File metadata

  • Download URL: localportmanager-1.0.3.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for localportmanager-1.0.3.tar.gz
Algorithm Hash digest
SHA256 14424890a64408f50630349b3badb1b4e0462e20dc44b513c3be87391203caa9
MD5 0596d221cff48283979ce7660982cd09
BLAKE2b-256 111731de6e56858c69113d09531ac948c39971cc8c81575d883c92f7dc0504fd

See more details on using hashes here.

File details

Details for the file localportmanager-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for localportmanager-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6ef42af47a5e357331ae1522aca22946e2f4e8b5112af00c54a6faa2e20293d7
MD5 126acb8cda0f1ca29133d259525fa743
BLAKE2b-256 03f4bbd6502f846e4f2768035606e5dc85206c547f538baa6d39af635f71716e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page