Skip to content

Instantly share code, notes, and snippets.

@lukas2511
Created February 2, 2019 15:45
Show Gist options
  • Save lukas2511/893eb73c6ea359cb777ed8daaab2359a to your computer and use it in GitHub Desktop.
Save lukas2511/893eb73c6ea359cb777ed8daaab2359a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import scapy.all
import sys
last_sync = 0
m = 9999
M = 0
length = 272
def pkt_callback(pkt):
global last_sync, m, M
data = bytes(pkt.payload.payload.payload)
if data[0] == 0x00:
last_sync = pkt.time
if data[0] == 0x08:
if last_sync == 0:
return
bars = int((pkt.time - last_sync) * 1000 * 1000)
lat = bars/10
if lat < m:
m = lat
if lat > M:
M = lat
stats = "min: %5.1f max: %5.1f cur: %5.1f" % (m, M, lat)
if bars > (length-len(stats)-1):
bars = (length-len(stats)-3) * "#" + ">>"
else:
bars = bars * "#" + (length - bars - len(stats) - 1) * "."
sys.stdout.write("\r" + bars + " " + stats)
sys.stdout.flush()
scapy.all.sniff(iface="enp0s20f0u3", prn=pkt_callback, filter="udp and (port 319 or port 320)", store=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment