Lantronix Discovery Protocol

From Lantronix Wiki!
Revision as of 23:48, 24 March 2015 by Gary marrs (talk | contribs) (Created page with "This example is a Python app in source code that shows how to search and find Lantronix Devices using a UDP broadcast. It is run from the command line. <br> === Prerequisit...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This example is a Python app in source code that shows how to search and find Lantronix Devices using a UDP broadcast. It is run from the command line.

Prerequisites

1) import socket, time and sys

Sample Code

  1. utility to search and find Lantronix devices
  2. written by:
  3. Gary Marrs
  4. Lantronix FAE
  5. garym@lantronix.com
  6. 03-20-15
  7. Rev 0.1

import socket #for sockets import sys #for exit import time

j = 0 k = 0 host = port = 30718 DATA = [] LTRXnode = [] packet = []

print "searching for Lantronix devices...\n"

  1. 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()


  1. Set the search string

msg = chr(0)+chr(0)+chr(0)+chr(0xf6)

try: s.sendto(msg, ("192.168.1.255", port)) except socket.error, msg: print 'Error Code : ' + str(msg[0]) + ' Message ' + msg[1] sys.exit()

  1. time.sleep(4)

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]) j += 1 except Exception: #print "no rcv" s.close()

time.sleep(1) t1 = time.clock() - t0 # find difference in time #print t1

  1. print out results of search

print "%d devices found " % j

for x in LTRXnode: print "%s %s " % (x,DATA[k]) k +=1

print "\n"

raw_input('Press the Enter Key to Exit\n')