-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathethtag.py
executable file
·36 lines (33 loc) · 1.07 KB
/
ethtag.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
#!/usr/bin/env python
import dpkt,sys
import binascii
import json
import caneton
if not len(sys.argv) == 3:
print("USAGE: "+sys.argv[0]+" candata.cap dbcfile.json")
print("outputs to stdout")
sys.exit(1)
capFile = open(sys.argv[1],'r')
with open(sys.argv[2]) as dbc_file:
dbc_json = json.loads(dbc_file.read())
pcap = dpkt.pcap.Reader(capFile)
for ts, buf in pcap:
print ts,
eth = dpkt.sll.SLL(buf)
ip = eth.data
udp = ip.data
if isinstance (udp, dpkt.udp.UDP):
if udp.sport == 20100:
packet=''.join(x.encode('hex') for x in str(udp))
message_id = int(packet[20:24],16)
message_data = binascii.unhexlify(packet[24:])
message_length = len(packet[24:]) / 2 # half the number number of hex characters
try:
message = caneton.message_decode(message_id, message_length, message_data, dbc_json)
print(message)
except:
print(packet+' decode failed ID: 0x'+packet[20:24])
else:
print "x"
else:
print "x"