Lantronix Discovery Protocol
Jump to navigation
Jump to search
This example is a Python application in source code that shows how to search and find Lantronix Devices. It is run from the command line.
The Lantronix Discovery protocol uses a UDP broadcast out port 77FE on a network interface. All Lantronix devices on that subnet will respond with 30 bytes of data.
Their MAC address is included in the 30 bytes
Prerequisites
1) import socket, time and sys
2) While this code could be incorporated and run from a PremierWave device, it was written and tested on a PC. (win 7)
Sample Code
# utility to search and find Lantronix devices import socket #for sockets import sys #for exit import time # Replace this with the IP address of your network interface # Or write a function that programmatically finds your IP address HOST = '192.168.1.100' PORT = 30718 DATA = [] LTRXnode = [] print "searching for Lantronix devices...\n" # create datagram udp socket try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.bind((HOST,PORT)) s.settimeout(2) except socket.error: print 'Failed to create socket' sys.exit() #Set the search string msg = chr(0)+chr(0)+chr(0)+chr(0xf6) try: s.sendto(msg, ('<broadcast>', PORT)) except socket.error, msg: print 'Error Code : ' + str(msg[0]) + ' Message ' + msg[1] sys.exit() t1 = 0 t0 = time.clock() # set start time while (t1<3): # loop for no more than 3 seconds try: # receive data from client (data, addr) d, address = s.recvfrom(128) packet = "".join("%02x" % ord(c) for c in d) if packet[6:8] == "f7": LTRXnode.append(address[0]) DATA.append(packet[48:60]) except Exception: s.close() time.sleep(1) t1 = time.clock() - t0 # find difference in time # print out results of search print "%d devices found " % len(LTRXnode) for idx, node in enumerate(LTRXnode): print "%s %s " % (node,DATA[idx]) print "\n" raw_input('Press the Enter Key to Exit\n')