# upnp **Repository Path**: MailiSoft/upnp ## Basic Information - **Project Name**: upnp - **Description**: 一个用python写的,配置upnp的服务端程序 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-07 - **Last Updated**: 2025-10-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # UPnP Manager A Python application for managing UPnP port mappings with a Gradio web interface. ## Features 1. **Port Mapping Management** - Query existing port mappings from your router - Add new port mappings through the interface or configuration file - Automatic repair of missing mappings based on configuration 2. **Web Interface (Gradio)** - Table view of all current port mappings - Form for adding new mappings - Log output showing operations and automatic repairs - Refresh button to update the mapping table 3. **Configuration File Management** - Define port mappings in a simple INI format - Automatic checking and repair of mappings based on configuration - Dynamic configuration reloading ## Installation 1. Install the required dependencies: ``` pip install -r requirements.txt ``` 2. Make sure your router has UPnP enabled ## Usage 1. Configure your port mappings in `config.ini`: ```ini [PORT_MAPPINGS] web = 80/TCP:192.168.1.100:80 game = 7777/UDP:192.168.1.101:25565 [SCHEDULER] interval_minutes = 1 ``` 2. Run the application: ``` python upnp_manager.py ``` 3. Access the web interface at `http://localhost:7860` (or the URL shown in the console) ## Configuration Format The configuration file (`config.ini`) has two sections: 1. `[PORT_MAPPINGS]` - Define your port mappings: - Format: `name = external_port/protocol:internal_ip:internal_port` - Example: `web = 80/TCP:192.168.1.100:80` 2. `[SCHEDULER]` - Configure the automatic checking: - `interval_minutes` - How often to check mappings (default: 1 minute) ## Automatic Repair The application automatically checks for missing mappings defined in the configuration file every minute (or as configured). If a mapping is missing, it will be automatically added back. ## Security Features - Validates that internal IPs are in private network ranges to prevent malicious redirection - All operations are logged for audit purposes ## Docker Deployment You can also run the application using Docker and Docker Compose: 1. Build and run the container: ``` docker-compose up -d ``` 2. Access the web interface at `http://localhost:7860` 3. To stop the container: ``` docker-compose down ``` ### Docker Configuration The application uses the host network mode (`network_mode: host`) which is required for UPnP discovery to work properly. This allows the container to directly access the host network and discover UPnP devices. The configuration file (`config.ini`) is mounted as a volume, so you can modify it without rebuilding the container. ## Troubleshooting - If you're having issues with UPnP discovery, make sure your router has UPnP enabled - Check that no firewall is blocking the application's network access - Verify that the internal IPs in your configuration are within your local network range