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.2.tar.gz (14.1 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: UPnPy-1.0.2.tar.gz
  • Upload date:
  • Size: 14.1 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.2.tar.gz
Algorithm Hash digest
SHA256 938af6ae097e7d7f90c1d4db65fe5a1060e0338f53692b22db818bda48958e79
MD5 234b7183e5f6f773c139d227125ad2b4
BLAKE2b-256 0f9dc955dd46c6f4d534c09ac5f1f3e27d1c2aa078b73b6dc6e9d5f9d997f280

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