mirror of
https://github.com/mjg59/python-broadlink.git
synced 2024-11-10 18:00:12 +01:00
allow to specify network interface for discover method
This commit is contained in:
parent
83f1c3fc93
commit
72cf09f9e4
11
broadlink/__init__.py
Executable file → Normal file
11
broadlink/__init__.py
Executable file → Normal file
@ -48,15 +48,16 @@ def gendevice(devtype, host, mac):
|
|||||||
else:
|
else:
|
||||||
return device(host=host, mac=mac)
|
return device(host=host, mac=mac)
|
||||||
|
|
||||||
def discover(timeout=None):
|
def discover(timeout=None, local_ip_address=None):
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
if local_ip_address is None:
|
||||||
s.connect(('8.8.8.8', 53)) # connecting to a UDP address doesn't send packets
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
local_ip_address = s.getsockname()[0]
|
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('.')
|
address = local_ip_address.split('.')
|
||||||
cs = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
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_REUSEADDR, 1)
|
||||||
cs.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
cs.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||||
cs.bind(('',0))
|
cs.bind((local_ip_address,0))
|
||||||
port = cs.getsockname()[1]
|
port = cs.getsockname()[1]
|
||||||
starttime = time.time()
|
starttime = time.time()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user