2020-10-23 00:42:57 -07:00
|
|
|
#!/usr/bin/env python
|
2020-01-15 01:24:15 -08:00
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
# LoRa PHYdecoder - parse LoRa PHY decoded by gr-lora
|
|
|
|
# Copyright (C) 2020 Sebastien Dudek (@FlUxIuS) at @PentHertz
|
|
|
|
|
2020-03-18 09:52:09 -07:00
|
|
|
from layers import LoRa
|
|
|
|
from scapy.layers.inet import UDP
|
|
|
|
from scapy.sendrecv import sniff
|
2020-01-15 01:24:15 -08:00
|
|
|
import argparse
|
|
|
|
|
2020-03-18 09:52:09 -07:00
|
|
|
|
2020-01-15 01:24:15 -08:00
|
|
|
def decodePHY(pkt):
|
|
|
|
decoded = LoRa(pkt[UDP].load)
|
|
|
|
print (repr(decoded))
|
|
|
|
|
2020-03-18 09:52:09 -07:00
|
|
|
|
2020-01-15 01:24:15 -08:00
|
|
|
def filterpkt(pkt, port):
|
|
|
|
if pkt.haslayer(UDP):
|
|
|
|
if pkt[UDP].dport == port:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2020-03-18 09:52:09 -07:00
|
|
|
|
2020-01-15 01:24:15 -08:00
|
|
|
if __name__ == "__main__":
|
2020-03-18 09:52:09 -07:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Monitor and decode MAC PHY packets.')
|
2020-01-15 01:24:15 -08:00
|
|
|
parser.add_argument('-p', '--port', dest='port', default=40868,
|
|
|
|
help='TAP PORT to listen on (default: UDP 40868)')
|
|
|
|
parser.add_argument('-i', '--iface', dest='iface', default='lo',
|
|
|
|
help='Interface to monitor (default: local)')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
iface = args.iface
|
|
|
|
port = int(args.port)
|
|
|
|
|
2020-03-18 09:52:09 -07:00
|
|
|
sniff(prn=decodePHY,
|
|
|
|
lfilter=lambda pkt: filterpkt(pkt, port),
|
|
|
|
iface=iface)
|