diff options
author | Matthew Garrett <mjg59@coreos.com> | 2016-12-25T11·07+0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-25T11·07+0000 |
commit | 877a7b7460f12c9dfa825e0548408c968de63494 (patch) | |
tree | 78c0a3ca0412d9da392484c54aa4758309273d72 | |
parent | a0a1c1b7a1726ee3bf96c1f2afd197ecad00d5e1 (diff) | |
parent | 72cf09f9e42a09b2fd806f3d5f08fb4b05ae4aab (diff) |
Merge pull request #34 from eschava/master
allow to specify network interface for discover method
-rw-r--r--[-rwxr-xr-x] | broadlink/__init__.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/broadlink/__init__.py b/broadlink/__init__.py index c00f79a8ce8d..37a7fcbec26c 100755..100644 --- a/broadlink/__init__.py +++ b/broadlink/__init__.py @@ -51,15 +51,16 @@ def gendevice(devtype, host, mac): else: return device(host=host, mac=mac) -def discover(timeout=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] +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] address = local_ip_address.split('.') cs = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) cs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) cs.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) - cs.bind(('',0)) + cs.bind((local_ip_address,0)) port = cs.getsockname()[1] starttime = time.time() |