Choose ports in range 17600-17650, so Tails can whitelist them (#220)

This commit is contained in:
Micah Lee 2016-02-27 18:03:42 +01:00
parent 738c05a5f8
commit 3ed1f964cb

View File

@ -51,11 +51,16 @@ class OnionShare(object):
def choose_port(self):
"""
Pick an un-used port to bind to.
Pick an un-used port in the range 17600-17650 to bind to.
"""
# let the OS choose a port
tmpsock = socket.socket()
tmpsock.bind(("127.0.0.1", 0))
for port in range(17600, 17650):
try:
tmpsock.bind(("127.0.0.1", port))
break
except OSError:
pass
self.port = tmpsock.getsockname()[1]
tmpsock.close()