Skip to content

Instantly share code, notes, and snippets.

@toxicantidote
Created August 5, 2021 04:53
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 toxicantidote/62a145f908803b092390515f88cc978f to your computer and use it in GitHub Desktop.
Save toxicantidote/62a145f908803b092390515f88cc978f to your computer and use it in GitHub Desktop.
Finds Fieldfox units on the LAN
import socket
import threading
import re
class FoxHunter(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.name = 'thread_FoxHunter'
self.units = []
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.bind(('', 987))
def run(self):
packet = self.sock.recvfrom(1024)
ip = packet[1][0]
data = packet[1].decode('utf-8', errors = 'ignore')
re_id = re.search(r'i\.MX31 SOM\-LV(\W+)(\w+)\;(\w+)\;', data)
if re_id:
info = dict()
model = re_id.group(2)
serial = re_id.group(3)
info['model'] = model
info['serial'] = serial
info['ip'] = ip
print('Found model ' + model + ' at ' + ip + ' - Serial ' + serial)
def add_unit(self, info):
for check in self.units:
if check['ip'] == info['ip']:
return
else:
self.units.append(info)
break
def get_units(self):
return self.units
foxh = FoxHunter()
foxh.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment