Improving the function to count the number of roads
[re6stnet.git] / upnpigd.py
1 import miniupnpc
2 import socket
3
4 # return (address, port)
5 def ForwardViaUPnP(local_port):
6 u = miniupnpc.UPnP()
7 u.discoverdelay = 200
8 u.discover()
9 u.selectigd()
10 external_port = 1194
11 while True:
12 while u.getspecificportmapping(external_port, 'UDP') != None:
13 external_port = max(externalPort + 1, 49152)
14 if external_port == 65536:
15 raise Exception
16 if u.addportmapping(external_port, 'UDP', u.lanaddr, local_port, 'Vifib openvpn server', ''):
17 return (u.externalipaddress(), external_port)
18