add python example to readme

This commit is contained in:
Jack Robison 2020-10-13 17:05:14 -04:00
parent 33bfa23273
commit 8a718789c7
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -86,6 +86,28 @@ By default, the network device will be automatically discovered. The interface m
aioupnp --interface=wlp4s0 --gateway_address=192.168.1.6 m_search aioupnp --interface=wlp4s0 --gateway_address=192.168.1.6 m_search
#### Example usage from python
from aioupnp.upnp import UPnP
async def main():
upnp = await UPnP.discover()
print(await upnp.get_external_ip())
print(await upnp.get_redirects())
print("adding a port mapping")
await upnp.add_port_mapping(1234, 'TCP', 1234, upnp.lan_address, 'test mapping')
print(await upnp.get_redirects())
print("deleting the port mapping")
await upnp.delete_port_mapping(1234, 'TCP')
print(await upnp.get_redirects())
asyncio.run(main())
## Troubleshooting ## Troubleshooting
#### Debug logging #### Debug logging