Created
August 5, 2021 04:53
-
-
Save toxicantidote/62a145f908803b092390515f88cc978f to your computer and use it in GitHub Desktop.
Finds Fieldfox units on the LAN
This file contains hidden or 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 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