A command-line utility to manage port mappings on your local router using UPnP/NAT-PMP
Project description
PortGate
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:
- Run a service on a specific port locally (e.g.,
python3 -m http.server 55000) - Use PortGate to create a port mapping through your router
- Access your service from the internet using your WAN IP and the mapped port
Requirements
- Python 3.8 or higher
miniupnpcPython library- Router with UPnP/NAT-PMP enabled
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file portgate-1.0.0.tar.gz.
File metadata
- Download URL: portgate-1.0.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c00b010cd08ba7eca06711412024418777ed1e49cb40de5bdbcf88789733324
|
|
| MD5 |
41ea25c0f16e474c84f7b8849f611412
|
|
| BLAKE2b-256 |
8d18ef9aa8c54c85df1dfc2e2692c42d148b746357c615519ee6a8ad95a7b410
|
File details
Details for the file portgate-1.0.0-py3-none-any.whl.
File metadata
- Download URL: portgate-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd5d450b592bff54f74187543d415f6e9ecbc58c6415510581c7afcde19caa7f
|
|
| MD5 |
545aa31e561ae65ff957c6ce5edccb02
|
|
| BLAKE2b-256 |
a8775c0e52afbdc5b48bb5abdf72db614558fef74dc7adab91e442e0375c12bf
|