Skip to content

Commit 23dac08

Browse files
authored
Add support for private IP range 10.0.0.0-10.255.255.255 (#10)
1 parent 874145f commit 23dac08

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

dance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class PairingMethod(Enum):
3636

3737

3838
REGEX_PAIRING_CODE = re.compile(r'^\d{6}$')
39-
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])$')
39+
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])$')
4040

4141

4242
async def get_device_ids():
@@ -249,7 +249,7 @@ def is_valid_pairing_method(val):
249249
def get_host_ip():
250250
try:
251251
for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
252-
if ip.startswith('192.168'):
252+
if ip.startswith('192.168') or ip.startswith('10.'):
253253
return ip
254254
except Exception:
255255
pass

joydance/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ async def hole_punching(self):
149149
''' Open a port on this machine so the console can connect to it '''
150150
try:
151151
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
152+
conn.settimeout(10)
152153
conn.bind(('0.0.0.0', self.host_port))
153154
conn.listen(5)
154155

@@ -382,7 +383,7 @@ async def connect_ws(self):
382383
if self.tls_certificate:
383384
ssl_context.load_verify_locations(cadata=self.tls_certificate)
384385

385-
if '192.168' in self.pairing_url:
386+
if self.pairing_url.startswith('192.168.') or self.pairing_url.startswith('10.'):
386387
if self.console_conn:
387388
server_hostname = self.console_conn.getpeername()[0]
388389
else:

static/js/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class PrivateIpAddress extends Component {
107107
let console_ip_addr = props.console_ip_addr
108108

109109
let hostname = window.location.hostname
110-
if (hostname.startsWith('192.168.')) {
110+
if (hostname.startsWith('192.168.') || hostname.startsWith('10.')) {
111111
host_ip_addr = hostname
112112
lock_host = true
113113
}
@@ -162,7 +162,7 @@ class PrivateIpAddress extends Component {
162162
`}
163163
164164
${([PairingMethod.FAST, PairingMethod.OLD].indexOf(pairing_method) > -1 || (pairing_method == PairingMethod.DEFAULT && !state.lock_host)) && html`
165-
<input required id="ipAddr" type="text" inputmode="decimal" size="15" maxlength="15" placeholder="192.168.x.x" pattern="^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])$" value=${addr} onKeyPress=${this.onKeyPress} onChange="${this.onChange}" />
165+
<input required id="ipAddr" type="text" inputmode="decimal" size="15" maxlength="15" placeholder="192.168.?/10.?" pattern="^(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])$" value=${addr} onKeyPress=${this.onKeyPress} onChange="${this.onChange}" />
166166
`}
167167
168168
`
@@ -385,7 +385,7 @@ class App extends Component {
385385
const state = this.state
386386
const pairing_method = state.pairing_method
387387
let addr = pairing_method == PairingMethod.DEFAULT ? state.host_ip_addr : state.console_ip_addr
388-
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])$/)) {
388+
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])$/)) {
389389
alert('ERROR: Invalid IP address!')
390390
document.getElementById('ipAddr').focus()
391391
return

0 commit comments

Comments
 (0)