From 23dac08e45ba771c7e9216163e9e1dcf38b13c5c Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sun, 24 Apr 2022 12:01:45 +0700 Subject: [PATCH] Add support for private IP range 10.0.0.0-10.255.255.255 (#10) --- dance.py | 4 ++-- joydance/__init__.py | 3 ++- static/js/app.js | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dance.py b/dance.py index 71c1ee5..3f1a2f9 100644 --- a/dance.py +++ b/dance.py @@ -36,7 +36,7 @@ class PairingMethod(Enum): REGEX_PAIRING_CODE = re.compile(r'^\d{6}$') -REGEX_LOCAL_IP_ADDRESS = re.compile(r'^192\.168\.((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.)(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$') +REGEX_LOCAL_IP_ADDRESS = re.compile(r'^(192\.168|10.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))\.((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.)(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$') async def get_device_ids(): @@ -249,7 +249,7 @@ def is_valid_pairing_method(val): def get_host_ip(): try: for ip in socket.gethostbyname_ex(socket.gethostname())[2]: - if ip.startswith('192.168'): + if ip.startswith('192.168') or ip.startswith('10.'): return ip except Exception: pass diff --git a/joydance/__init__.py b/joydance/__init__.py index 3c45a41..7d98235 100644 --- a/joydance/__init__.py +++ b/joydance/__init__.py @@ -149,6 +149,7 @@ class JoyDance: ''' Open a port on this machine so the console can connect to it ''' try: conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + conn.settimeout(10) conn.bind(('0.0.0.0', self.host_port)) conn.listen(5) @@ -382,7 +383,7 @@ class JoyDance: if self.tls_certificate: ssl_context.load_verify_locations(cadata=self.tls_certificate) - if '192.168' in self.pairing_url: + if self.pairing_url.startswith('192.168.') or self.pairing_url.startswith('10.'): if self.console_conn: server_hostname = self.console_conn.getpeername()[0] else: diff --git a/static/js/app.js b/static/js/app.js index f0b4d14..86feb64 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -107,7 +107,7 @@ class PrivateIpAddress extends Component { let console_ip_addr = props.console_ip_addr let hostname = window.location.hostname - if (hostname.startsWith('192.168.')) { + if (hostname.startsWith('192.168.') || hostname.startsWith('10.')) { host_ip_addr = hostname lock_host = true } @@ -162,7 +162,7 @@ class PrivateIpAddress extends Component { `} ${([PairingMethod.FAST, PairingMethod.OLD].indexOf(pairing_method) > -1 || (pairing_method == PairingMethod.DEFAULT && !state.lock_host)) && html` - + `} ` @@ -385,7 +385,7 @@ class App extends Component { const state = this.state const pairing_method = state.pairing_method let addr = pairing_method == PairingMethod.DEFAULT ? state.host_ip_addr : state.console_ip_addr - if (!addr.match(/^192\.168\.((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.)(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/)) { + if (!addr.match(/^(192\.168|10.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))\.((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.)(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/)) { alert('ERROR: Invalid IP address!') document.getElementById('ipAddr').focus() return