1
0
mirror of https://github.com/mjg59/python-broadlink.git synced 2024-11-21 22:51:41 +01:00

Rollback to old address lookup logic (#378)

This commit is contained in:
Felipe Martins Diel 2020-06-08 07:20:44 -03:00 committed by GitHub
parent 4b90e437a0
commit d0dcf06e2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,11 +77,10 @@ def gendevice(devtype, host, mac, name=None, cloud=None):
def discover(timeout=None, local_ip_address=None, discover_ip_address='255.255.255.255'):
if local_ip_address is None:
local_ip_address = socket.gethostbyname(socket.gethostname())
if local_ip_address.startswith('127.'):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.connect(('8.8.8.8', 53)) # connecting to a UDP address doesn't send packets
local_ip_address = s.getsockname()[0]
address = local_ip_address.split('.')
cs = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
cs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)