Remove \t from upnpigd.py
[re6stnet.git] / upnpigd.py
1 import miniupnpc
2 import socket
3
4 # return (address, port)
5 def ForwardViaUPnP(localPort):
6 u = miniupnpc.UPnP()
7 u.discoverdelay = 200
8 u.discover()
9 u.selectigd()
10 externalPort = 1194
11 while True:
12 while u.getspecificportmapping(externalPort, 'UDP') != None:
13 externalPort = max(externalPort + 1, 49152)
14 if externalPort == 65536:
15 raise Exception
16 if u.addportmapping(externalPort, 'UDP', u.lanaddr, localPort, 'Vifib openvpn server', ''):
17 return (u.externalipaddress(), externalPort)
18
19 # TODO : specify a lease duration