From 3ed1f964cb5b66fa9af5df229c37323ef1e3aa46 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 27 Feb 2016 18:03:42 +0100 Subject: [PATCH] Choose ports in range 17600-17650, so Tails can whitelist them (#220) --- onionshare/onionshare.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index fa882fd6..34e64b05 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -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()