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

Allow setting custom discover ip port

This commit is contained in:
Daan Klijn 2020-08-10 21:28:09 +02:00 committed by Matthew Garrett
parent fe4aa5b991
commit 8167736588

View File

@ -109,7 +109,12 @@ def gendevice(dev_type, host, mac, name=None, is_locked=None):
) )
def discover(timeout=None, local_ip_address=None, discover_ip_address='255.255.255.255'): def discover(
timeout=None,
local_ip_address=None,
discover_ip_address='255.255.255.255',
discover_ip_port=80
):
if local_ip_address is None: if local_ip_address is None:
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: 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 s.connect(('8.8.8.8', 53)) # connecting to a UDP address doesn't send packets
@ -164,7 +169,7 @@ def discover(timeout=None, local_ip_address=None, discover_ip_address='255.255.2
packet[0x20] = checksum & 0xff packet[0x20] = checksum & 0xff
packet[0x21] = checksum >> 8 packet[0x21] = checksum >> 8
cs.sendto(packet, (discover_ip_address, 80)) cs.sendto(packet, (discover_ip_address, discover_ip_port))
if timeout is None: if timeout is None:
response = cs.recvfrom(1024) response = cs.recvfrom(1024)
responsepacket = bytearray(response[0]) responsepacket = bytearray(response[0])