some boxes on 10.x.x.x/8 would crash

This commit is contained in:
ed 2020-05-01 02:17:59 +02:00
parent bef2e92cef
commit 060368e93d
3 changed files with 35 additions and 8 deletions

2
.vscode/launch.json vendored
View file

@ -15,7 +15,7 @@
"-a",
"ed:wark",
"-v",
"/home/ed/inc:inc:r:aed"
"srv::r:aed"
]
},
{

View file

@ -2,9 +2,24 @@
from __future__ import print_function, unicode_literals
import os
import sys
import ssl
import socket
try:
import jinja2
except ImportError:
print(
"""\033[1;31m
you do not have jinja2 installed,\033[33m
choose one of these:\033[0m
* apt install python-jinja2
* python3 -m pip install --user jinja2
* (try another python version, if you have one)
* (try copyparty.sfx instead)
"""
)
sys.exit(1)
from .__init__ import E
from .util import Unrecv

View file

@ -92,11 +92,23 @@ class TcpSrv(object):
default_route = None
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
for ip in [
"10.255.255.255",
"172.31.255.255",
"192.168.255.255",
"239.255.255.255",
# could add 1.1.1.1 as a final fallback
# but external connections is kinshi
]:
try:
s.connect(("10.255.255.255", 1))
s.connect((ip, 1))
# raise OSError(13, "a")
default_route = s.getsockname()[0]
break
except (OSError, socket.error) as ex:
if ex.errno not in [101, 10065]:
if ex.errno == 13:
self.log("tcpsrv", "eaccess {} (trying next)".format(ip))
elif ex.errno not in [101, 10065]:
raise
s.close()