Inspired from the miniupnpc python script

This commit is contained in:
Louis Lacoste 2022-09-13 16:48:10 +02:00
parent 8e8bc648ae
commit a169009171
2 changed files with 25 additions and 3 deletions

View file

@ -1,5 +1,5 @@
{
"service-name":["Description", internal_port, external_port],
"web":["Web HTTP port", 80, 80],
"web-secure":["Web HTTPS port", 443, 443]
"service-name":["Description", internal_port, external_port, 'protocol'],
"web":["Web HTTP port", 80, 80, 'TCP'],
"web-secure":["Web HTTPS port", 443, 443, 'TCP']
}

View file

@ -1,2 +1,24 @@
#!/usr/bin/python3
import miniupnpc
import sys
u = miniupnpc.UPnP(None, None, 200, 0)
u.lanaddr
u.discover()
try:
u.selectigd()
except Exception as e:
print("Exception : ", e)
sys.exit(1)
print('local ip address :', u.lanaddr)
print('external ip address :', u.externalipaddress())
print( u.statusinfo(), u.connectiontype())
print('total bytes : sent', u.totalbytesent(), 'received', u.totalbytereceived())
print('total packets : sent', u.totalpacketsent(), 'received', u.totalpacketreceived())
print(u.addportmapping(12000, 'TCP', u.lanaddr, 12000, 'test port mapping', ''))
input("Hit any key to interrupt port mapping")
print(u.deleteportmapping(12000, 'TCP'))