An example code to advertise a device on a network using UPnP/SSDP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib Init. Oct 22, 2016
.gitignore Init. Oct 22, 2016
LICENCE Init. Oct 22, 2016 Init. Oct 22, 2016 Init. Oct 22, 2016
a-upnp-device-visible-in-the-network-center-of-windows-10.png Init. Oct 22, 2016
requirements.txt Add requirements file. Oct 22, 2016

Python UPnP Example


This code implements a SSDP server and a HTTP server, in order to notify the network that a device is here.

The base of this code was the SSDP module of coherence . I took it, converted it to Python 3, and kept only the interesting parts for this project: the parts that responds to MSEARCH queries.

Our device is the network view of Windows 10

Technical details

First, a SSDP client will try to search devices on the network by issuing a MSEARCH * query:


lib/ will handle it and reply with a 200:

HTTP/1.1 200 OK
SERVER: ZeWaren example SSDP Server
USN: uuid:e427ce1a-3e80-43d0-ad6f-89ec42e46363::upnp:rootdevice
CACHE-CONTROL: max-age=1800
last-seen: 1477147409.432466
ST: upnp:rootdevice
DATE: Sat, 22 Oct 2016 14:44:26 GMT

The client will then fetch the device description:

GET /jambon-3000.xml HTTP/1.1
Cache-Control: no-cache
Connection: Keep-Alive
Pragma: no-cache
Accept: text/xml, application/xml
User-Agent: FDSSDP

And lib/ will build and serve that file:

HTTP/1.0 200 OK
Server: BaseHTTP/0.6 Python/3.4.3
Date: Sat, 22 Oct 2016 14:44:26 GMT
Content-type: application/xml

        <friendlyName>Jambon 3000</friendlyName>
        <manufacturer>Boucherie numrique SAS</manufacturer>
        <modelDescription>Jambon Appliance 3000</modelDescription>

The client now knows (nearly) everything about the device.

Relevant links