Skip to main content

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

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

Metadata

Release files for portgate 1.0.1

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

Source distribution (sdist)

Source distribution for portgate 1.0.1
File Size Uploaded
portgate-1.0.1.tar.gz 7.8 kB Details

Built distribution (wheel)

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

Total release size: 15.8 kB

Release files / portgate-1.0.1.tar.gz

Download URL portgate-1.0.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a3cf6afebe5a82b378a317e7a86ed01ded9d60706242a6187b235ee61421f278
BLAKE2b-256 checksum
How to use checksums
afc28b0661262bcbc02ab7458b9951063fc6fa217da26b00ed4147de45a78b49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.11

Release files / portgate-1.0.1-py3-none-any.whl

Download URL portgate-1.0.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a452efb08db9b1e5b92256c61249fe1c3fbd2eeac3571eb5c5db022d1c5f422b
BLAKE2b-256 checksum
How to use checksums
ec7140503a05acf5b850bd6969d60457e75e45fe524b549ac1d26edb2089eea5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.11

Release history Release notifications | RSS feed

This release

1.0.1 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