Add support for specifying destination IP address to use in discovery (#313)

Co-authored-by: Kja64 <Ken@lkv20.dk>
This commit is contained in:
Daniel Høyer Iversen 2020-03-04 22:25:00 +01:00 committed by GitHub
parent ec4df39665
commit e84becd05b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View file

@ -63,7 +63,7 @@ def gendevice(devtype, host, mac):
return device_class(host=host, mac=mac, devtype=devtype)
def discover(timeout=None, local_ip_address=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.'):
@ -116,7 +116,7 @@ def discover(timeout=None, local_ip_address=None):
packet[0x20] = checksum & 0xff
packet[0x21] = checksum >> 8
cs.sendto(packet, ('255.255.255.255', 80))
cs.sendto(packet, (discover_ip_address, 80))
if timeout is None:
response = cs.recvfrom(1024)
responsepacket = bytearray(response[0])