From 790edb9a9dedbfc4f4645c0cb3553e6459c1c39a Mon Sep 17 00:00:00 2001 From: Anil Daoud Date: Tue, 21 May 2019 23:02:51 +0800 Subject: [PATCH] cleaner local ip address lookup --- broadlink/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/broadlink/__init__.py b/broadlink/__init__.py index 582f64d..c3b2cec 100644 --- a/broadlink/__init__.py +++ b/broadlink/__init__.py @@ -63,9 +63,7 @@ def gendevice(devtype, host, mac): def discover(timeout=None, local_ip_address=None): if local_ip_address is None: - 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] + local_ip_address = socket.gethostbyname(socket.gethostname()) address = local_ip_address.split('.') cs = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) cs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)