Skip to main content

Lightweight UPnP client library for Python.

Project description

UPnPy

Build Status PyPI - Python Version MIT License

Lightweight UPnP client library for Python.

Examples

Get the external IP address of an Internet Gateway Device:

import upnpy

upnp = upnpy.UPnP()
upnp.discover()  # Discover UPnP devices on the network

upnp.select_igd()  # Select the IGD

# Select the service which implements the "GetExternalIPAddress" action
# Some routers don't implement WANIPConnection but WANPPPConnection instead:
# urn:schemas-upnp-org:service:WANPPPConnection:1
upnp.select_service('urn:schemas-upnp-org:service:WANIPConnection:1')

# Execute the "GetExternalIPAddress" action
upnp.execute('GetExternalIPAddress')

If the above code executed successfully, it should return a dictionary containing the external IP Address:

{'NewExternalIPAddress': 'xxx.xxx.xxx.xxx'}

Add a new port mapping to an Internet Gateway Device:

import upnpy

upnp = upnpy.UPnP()
upnp.discover()  # Discover UPnP devices on the network

upnp.select_igd()  # Select the IGD

# Select the service which implements the "AddPortMapping" action
# Some routers don't implement WANIPConnection but WANPPPConnection instead:
# urn:schemas-upnp-org:service:WANPPPConnection:1
upnp.select_service('urn:schemas-upnp-org:service:WANIPConnection:1')

# Execute the "AddPortMapping" action
upnp.execute('AddPortMapping', 80, 'TCP', 8000, '192.168.1.3', 'Test UPnPy entry')

If the above code executed successfully, a new port mapping should've been created on your router.

80 is the port that will be opened on the WAN side of the router

TCP is the transport protocol you want to use (can also be UDP)

8000 is the port of the internal client where a server will be listening

192.168.1.3 is the IP of the internal client where connections should be forwarded to

Test UPnPy entry is a description of the port mapping.

Returns an empty dictionary:

{}

Documentation

Documentation is available at https://upnpy.readthedocs.io

License

This project is licensed under the terms of the MIT License.

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

UPnPy-1.0.4.tar.gz (14.5 kB view details)

Uploaded Source

File details

Details for the file UPnPy-1.0.4.tar.gz.

File metadata

  • Download URL: UPnPy-1.0.4.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for UPnPy-1.0.4.tar.gz
Algorithm Hash digest
SHA256 a9ca0a46b08d7099bb8fad79f2ca8f54e6e926d677aa6ebb4e3c4883d9559bab
MD5 5082cd9bbed712d464040755db9e4039
BLAKE2b-256 26153bd39bd4d90fa38ec6c3ee6206bce74e0858bc6c615e1146ea116ea464ef

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