-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprint-traceroute.py
37 lines (24 loc) · 1005 Bytes
/
print-traceroute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from pubsub import pub
import time
import meshtastic.serial_interface, meshtastic.tcp_interface
interface = meshtastic.serial_interface.SerialInterface()
# interface = meshtastic.tcp_interface.TCPInterface(hostname="192.168.86.39")
dest = 1623194643
hopLimit = 5
channelIndex = 0
interface.sendTraceRoute(dest, hopLimit, channelIndex=channelIndex)
def onReceive(packet, interface):
if 'decoded' in packet and packet['decoded']['portnum'] == 'TRACEROUTE_APP':
routeBack = packet['decoded']['traceroute'].get('routeBack', [])
route = packet['decoded']['traceroute'].get('route', [])
message = f"{packet['to']}"
if routeBack:
message += f" --> {' --> '.join(map(str, routeBack))}"
message += f" --> {packet['from']}"
if route:
message += f" --> {' --> '.join(map(str, route))}"
message += f" --> {packet['to']}"
print(message)
pub.subscribe(onReceive, 'meshtastic.receive')
while True:
time.sleep(1)