Allow first local ip find method to fail

This commit is contained in:
shortcutme 2018-08-13 02:44:50 +02:00
parent 84b36e72e4
commit c89170a22d
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -129,14 +129,17 @@ def _parse_igd_profile(profile_xml):
def _get_local_ips(): def _get_local_ips():
local_ips = [] local_ips = []
# get local ip using UDP and a broadcast address try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # get local ip using UDP and a broadcast address
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Not using <broadcast> because gevents getaddrinfo doesn't like that s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
# using port 1 as per hobbldygoop's comment about port 0 not working on osx: # Not using <broadcast> because gevents getaddrinfo doesn't like that
# https://github.com/sirMackk/ZeroNet/commit/fdcd15cf8df0008a2070647d4d28ffedb503fba2#commitcomment-9863928 # using port 1 as per hobbldygoop's comment about port 0 not working on osx:
s.connect(('239.255.255.250', 1)) # https://github.com/sirMackk/ZeroNet/commit/fdcd15cf8df0008a2070647d4d28ffedb503fba2#commitcomment-9863928
local_ips.append(s.getsockname()[0]) s.connect(('239.255.255.250', 1))
local_ips.append(s.getsockname()[0])
except:
pass
# Get ip by using UDP and a normal address (google dns ip) # Get ip by using UDP and a normal address (google dns ip)
try: try: