Last active
November 25, 2022 07:34
-
-
Save mgmarino/867b266e66b50840d5ab to your computer and use it in GitHub Desktop.
Find Lantronix XPort devices with a python script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import numpy | |
numpy.set_printoptions(formatter={'int':lambda x:hex(int(x))}) | |
def find_lantronix(timeout=4): | |
""" | |
Broadcasts to find xport devices on the current subnet. | |
""" | |
# Set up the socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.bind(('', 0)) | |
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
send_data = numpy.array([0x0, 0x0, 0x0, 0xF8], dtype=numpy.uint8) | |
s.sendto(send_data, ('<broadcast>', 30718)) | |
s.settimeout(timeout) | |
found_devices = {} | |
while 1: | |
try: | |
dat, (ip, _) = s.recvfrom(4096) | |
num_array = numpy.fromstring(dat, dtype=numpy.uint8) | |
if len(num_array) != 124: | |
print "Wrong device responding?" | |
continue | |
found_devices[ip] = dict(data=num_array) | |
except socket.timeout: | |
break | |
return found_devices | |
print find_lantronix() |
@tonipetrovic It's been a very long time since I've done this, so I'm not sure I can be too much help. But that sounds like more of an issue with how broadcast/UDF packets are forwarded between your two network types/other subnets. In other words, it may be rather an issue with how your network is configured. Good luck!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Michael,
tank you for this code. It works great for finding xport devices, but only when the computer is connected to the net via cable, but it is not working if you are connected via WIFI. Is it possible to broadcasts over WIFI (the computer is connected to the network via WIFI and xport is connected via cable)?
Thank you and kind regards,
Toni