Skip to content

Instantly share code, notes, and snippets.

@mgmarino
Last active November 25, 2022 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgmarino/867b266e66b50840d5ab to your computer and use it in GitHub Desktop.
Save mgmarino/867b266e66b50840d5ab to your computer and use it in GitHub Desktop.
Find Lantronix XPort devices with a python script.
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
Copy link

tonipetrovic commented Nov 24, 2022

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

@mgmarino
Copy link
Author

@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