ssdp_upnp
Introduction
The acticle Exploring UPnP with Python gives a realy good insight of UPNP. SSDP is one of it's implementation.
The packege includes three individual Classes, ssdp server, ssdp client, nat upnp class. They first two class inherits from Class threading.Thread class, thus the two class instance runs on a single thread of own. They will not block main thread. After the ssdp client find a peer with same product name, it can communicate with main thread by queue. Nat upnp class is running on main thread, thus it will not block I/O, it will just search for LAN GDI (router with upnp nap forwarding function), and bind internal port with external port.
The logic of server is just listen a broadcast address with port 1900. If it received a "M-SEARCH" message, it will responce it's service infomation. The client just send a broadcast message with "M-SEARCH", and get server's service infomation.
The package can be used in blockchain solution where peers to find each other in LAN environment.
API
Server Class
run(): run the server in main thread with I/O blocking
start(): run the server in other thread with I/O nonblocking
stop(): stop the server
Client
run(): run the client in main thread with I/O blocking
start(): run the client in other thread with I/O nonblocking
stop(): stop the client
Nat
addPortForward(internal_port, external_port): run the function in main thread. It returns None if fail to bind, returns a tuple (external_ip, external_port) if succeed.
removePortForward(external_port): run the function in main thread. It returns True if succeed, and returns False if failed.
example
pip install ssdp-upnp
import sys
from ssdp_upnp.ssdp import Server, Client, Nat
from ssdp_upnp.ssdp import gen_logger
from queue import Queue
logger = gen_logger('sample')
if __name__ == '__main__':
try:
if sys.argv[1] == 'server':
upnpServer = Server(8048, 'blockchain', 'main')
upnpServer.start()
elif sys.argv[1] == 'client':
queue = Queue()
upnpClient = Client('blockchain', 'main', queue)
upnpClient.start()
logger.info(queue.get())
elif sys.argv[1] == 'nat':
nat = Nat()
print(nat.addPortForward(8011, 8015))
else:
logger.warning('need params server or clinet')
except Exception as e:
logger.error(e)
Metadata
Release files for ssdp-upnp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ssdp_upnp-0.1.0.tar.gz | 4.4 kB | Without provenance | Details for ssdp_upnp-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ssdp_upnp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ssdp_upnp-0.1.0-py3-none-any.whl |
Total release size: 10.1 kB
Release files / ssdp_upnp-0.1.0.tar.gz
| Download URL | ssdp_upnp-0.1.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d680668a28922b5fbb4f69c5209df147d6dadbc2ecaea65fd8016c8f7db5b28
|
|
BLAKE2b-256 checksum How to use checksums |
552a9af87f5eb75c0db21d6efbab681bf201ff19775995ffa5f67995b6f097a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
|
Release files / ssdp_upnp-0.1.0-py3-none-any.whl
| Download URL | ssdp_upnp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
804b2fd4c8a5b3f9c1e3c114b67154da86096bc04e266bbdaf58eca662f67f2a
|
|
BLAKE2b-256 checksum How to use checksums |
9ce54ee71fdbda73d5161b0af5f39b55475b1ea19d38668a211b9de8198a0550
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
|
Security for ssdp-upnp 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.