33 lines
940 B
Python
33 lines
940 B
Python
import argparse
|
|
import re
|
|
|
|
class Event:
|
|
def __init__(self, tag, timestamp, event_type, pipe, usb_id, data):
|
|
self.tag = tag
|
|
self.timestamp = timestamp
|
|
self.event_type = event_type
|
|
self.pipe = pipe
|
|
self.usb_id = usb_id
|
|
self.data = data
|
|
|
|
def parseEvent(line):
|
|
usb_id = re.search(r'\d{1,2}:\d{1,3}:\d{1,2}', line)[0]
|
|
return Event(line[0:16],
|
|
line[17:28],
|
|
line[28],
|
|
line[30:32],
|
|
usb_id,
|
|
line.split(usb_id,1)[1][1:].strip())
|
|
|
|
parser = argparse.ArgumentParser(description='Parser to help read usbmon logs.')
|
|
parser.add_argument('-f', '--file', type=str, help='Path to log file')
|
|
args = parser.parse_args()
|
|
file_path = args.file
|
|
|
|
with open(file_path) as f:
|
|
lines = f.readlines()
|
|
for line in lines:
|
|
e = parseEvent(line)
|
|
print(e.event_type, e.pipe, e.usb_id, e.data)
|
|
f.close()
|