mirror of
https://github.com/mjg59/python-broadlink.git
synced 2024-11-22 07:00:12 +01:00
Add support for specifying destination IP address to use in discovery (#313)
Co-authored-by: Kja64 <Ken@lkv20.dk>
This commit is contained in:
parent
ec4df39665
commit
e84becd05b
@ -63,7 +63,7 @@ def gendevice(devtype, host, mac):
|
|||||||
return device_class(host=host, mac=mac, devtype=devtype)
|
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:
|
if local_ip_address is None:
|
||||||
local_ip_address = socket.gethostbyname(socket.gethostname())
|
local_ip_address = socket.gethostbyname(socket.gethostname())
|
||||||
if local_ip_address.startswith('127.'):
|
if local_ip_address.startswith('127.'):
|
||||||
@ -116,7 +116,7 @@ def discover(timeout=None, local_ip_address=None):
|
|||||||
packet[0x20] = checksum & 0xff
|
packet[0x20] = checksum & 0xff
|
||||||
packet[0x21] = checksum >> 8
|
packet[0x21] = checksum >> 8
|
||||||
|
|
||||||
cs.sendto(packet, ('255.255.255.255', 80))
|
cs.sendto(packet, (discover_ip_address, 80))
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
response = cs.recvfrom(1024)
|
response = cs.recvfrom(1024)
|
||||||
responsepacket = bytearray(response[0])
|
responsepacket = bytearray(response[0])
|
||||||
|
@ -7,10 +7,11 @@ import broadlink
|
|||||||
parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
|
parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
|
||||||
parser.add_argument("--timeout", type=int, default=5, help="timeout to wait for receiving discovery responses")
|
parser.add_argument("--timeout", type=int, default=5, help="timeout to wait for receiving discovery responses")
|
||||||
parser.add_argument("--ip", default=None, help="ip address to use in the discovery")
|
parser.add_argument("--ip", default=None, help="ip address to use in the discovery")
|
||||||
|
parser.add_argument("--dst-ip", default=None, help="destination ip address to use in the discovery")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print("Discovering...")
|
print("Discovering...")
|
||||||
devices = broadlink.discover(timeout=args.timeout, local_ip_address=args.ip)
|
devices = broadlink.discover(timeout=args.timeout, local_ip_address=args.ip, discover_ip_address=args.dst_ip)
|
||||||
for device in devices:
|
for device in devices:
|
||||||
if device.auth():
|
if device.auth():
|
||||||
print("###########################################")
|
print("###########################################")
|
||||||
|
Loading…
Reference in New Issue
Block a user