Created
March 26, 2021 13:14
-
-
Save sybip/219a900cc23acc9234f45cdb94e5c2a7 to your computer and use it in GitHub Desktop.
goTenna Mesh traffic logger, similar to (and based on) metalogger, but also including cleartext dump when practical
This file contains 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
#!/usr/bin/env python | |
""" | |
goTenna mesh message logger, using USB connected gtm-lab receiver | |
more info at: https://github.com/sybip/gtm-lab | |
""" | |
import serial | |
import sys | |
from time import gmtime, strftime | |
from binascii import unhexlify | |
# from pyGT https://github.com/sybip/pyGT | |
from gtairobj import gtReadAirMsg | |
from compatGTA import gtReadGTABlob | |
from gtdefs import MSG_CLASS_NAME | |
try: | |
ser = serial.Serial(port=sys.argv[1], baudrate=115200, timeout=1) | |
except IndexError: | |
print("ERROR: Please run as %s PORT_NAME" % sys.argv[0]) | |
sys.exit() | |
except serial.serialutil.SerialException: | |
print("ERROR: Could not open port: %s" % sys.argv[1]) | |
sys.exit() | |
print('Connected to %s, Ctrl-C to quit' % sys.argv[1]) | |
while True: | |
try: | |
x = ser.readline() | |
except KeyboardInterrupt: | |
break | |
x = x.rstrip() | |
if x: | |
x = x.decode('utf8') | |
else: | |
continue | |
# Received message lines syntax: RX_MSG:XXXX|DATA_OBJECT_HEX | |
if (x[0:7] == 'RX_MSG:'): | |
(a, msgObj, ) = x.split('|') | |
m = gtReadAirMsg(unhexlify(msgObj), 0) | |
if not m: # could not parse | |
print('(parsing error)') | |
print(msgObj) | |
continue | |
else: | |
continue # not a RX message | |
try: | |
destStr = '%012x:%02x' % (m['destGID'], m['destTag']) | |
except KeyError: | |
destStr = '[ALL] ' | |
try: | |
print("%s %s app=%04x %012x->%15s len=%3d h=%04x %s" % ( | |
strftime('%Y%m%d-%H%M%S', gmtime()), | |
MSG_CLASS_NAME[m['classID']], | |
m['appID'], m['fromGID'], destStr, len(m['msgBlob']), | |
m['hashID'], 'ENC' if m['cryptFlag'] else 'CLR')) | |
except (KeyError): | |
print('(unknown format)') | |
continue | |
if (('msgBlob' in m) and not m['cryptFlag']): | |
try: | |
res = gtReadGTABlob(m['msgBlob']) | |
except (ValueError): | |
continue | |
if res: | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment