From d0dcf06e2fe167c74ed55f9441ea4423950a0471 Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel <41558831+felipediel@users.noreply.github.com> Date: Mon, 8 Jun 2020 07:20:44 -0300 Subject: [PATCH] Rollback to old address lookup logic (#378) --- broadlink/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/broadlink/__init__.py b/broadlink/__init__.py index 73f64da..35ce629 100644 --- a/broadlink/__init__.py +++ b/broadlink/__init__.py @@ -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) - s.connect(('8.8.8.8', 53)) # connecting to a UDP address doesn't send packets - local_ip_address = s.getsockname()[0] + 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)