Skip to main content

A command-line utility to manage port mappings on your local router using UPnP/NAT-PMP

Project description

PortGate

PyPI PyPI - Python Version PyPI - License Downloads

A command-line utility to manage port mappings on your local router using UPnP/NAT-PMP. Easily open, close and list ports to expose local services (web servers, game servers, etc.) to the internet without Ngrok, Cloudflare, Serveo, etc.

Quick Start

Just run the following command to open a port on your router.

pip install portgate
portgate <local_port>

Features

  • Open new port mappings with custom descriptions and TTL
  • Remove existing port mappings
  • List all active port mappings
  • Refresh/renew specific port mappings
  • Clear all port mappings created by PortGate
  • Display router information and WAN IP

Installation

Use pip to install PortGate.

pip install portgate

Usage

Quick Mode (Recommended)

Just specify the local port you want to forward to the internet.

portgate <local_port>

Example:

sarp@IdeaPad:~$ portgate 8000
Port forwarding established!
External address: 95.65.xxx.xxx:1025
Internal address: localhost:8000
Press Ctrl+C to stop forwarding...
^C
Removing port mapping 1025 -> 8000...
Port mapping removed successfully.

Command Line Interface

portgate <command> <options>

Commands

Command Description
add Open a new port mapping
remove Remove an existing port mapping
list List all active port mappings
refresh Refresh/renew a specific mapping
clear Remove all mappings by PortGate
info Show router & WAN IP info

Options for add

Option Description Default
-p, --port Internal port to forward Required
-e, --external External port Same as int.
-P, --protocol Protocol: TCP, UDP, or BOTH TCP
-d, --desc Description for the mapping "PortGate"
-t, --ttl Lease duration in seconds (0 = infinite) 3600

Examples

# Map TCP port 8080 on WAN to port 8080 on local host, permanent
portgate add -p 8080 -P TCP -t 0

# Map external port 50000 to internal port 25565
portgate add -p 25565 -P TCP -e 50000

# Remove TCP port 8080 mapping
portgate remove -p 8080 -P TCP

# List current UPnP/NAT-PMP mappings
portgate list

# Display router info and public IP
portgate info

How It Works

PortGate uses the miniupnpc Python library to communicate with your router via UPnP/NAT-PMP protocols. This allows you to:

  1. Run a service on a specific port locally (e.g., python3 -m http.server 55000)
  2. Use PortGate to create a port mapping through your router
  3. Access your service from the internet using your WAN IP and the mapped port

Requirements

  • Python 3.8 or higher
  • miniupnpc Python library
  • Router with UPnP/NAT-PMP enabled

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

portgate-0.1.dev1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

portgate-0.1.dev1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file portgate-0.1.dev1.tar.gz.

File metadata

  • Download URL: portgate-0.1.dev1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.11

File hashes

Hashes for portgate-0.1.dev1.tar.gz
Algorithm Hash digest
SHA256 c90168ea9894fe0fcecb2c2cfa8abaa6d8b831bb8c35bc69d3505cb13b314c93
MD5 8058270752c23f46ec053ddd9ef32143
BLAKE2b-256 9cdff0694e53b80ff889d2c3563a514a71d8ca02240c5bc96638ab1e61896159

See more details on using hashes here.

File details

Details for the file portgate-0.1.dev1-py3-none-any.whl.

File metadata

  • Download URL: portgate-0.1.dev1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.11

File hashes

Hashes for portgate-0.1.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 01b833abf029cea5c66aacf6d1bf37daa1de9985de43a0f1e983d3cee6bae034
MD5 a254cfe064ed0075c998d015e5f57647
BLAKE2b-256 dcacd97e4a10b86a4e835e8305b93d04a2b89531012331c5c3a887abd53556c5

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