Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
import sys
from scapy.utils import rdpcap
from scapy.packet import Raw
from scapy.layers.bluetooth import L2CAP_Hdr
from statistics import mean, stdev
def get_hid_pkt_intervals(packets):
prev = 0
first = 1
intervals = []
for pkt in packets:
if pkt.haslayer(L2CAP_Hdr) and pkt.haslayer(Raw) and pkt[Raw].load[0] == 0xA1:
cur = pkt.time
interval = cur - prev
prev = cur
if first:
first = 0
continue
intervals.append(interval * 1000)
return intervals
def print_stats(intervals):
print("Samples: {}".format(len(intervals)))
print("Average: {:.6f} ms".format(mean(intervals)))
print("Max : {:.6f} ms".format(max(intervals)))
print("Min : {:.6f} ms".format(min(intervals)))
print("Std Dev: {:.6f} ms".format(stdev(intervals)))
if __name__ == '__main__':
print_stats(get_hid_pkt_intervals(rdpcap(sys.argv[1])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment