-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheth2csv.py
More file actions
executable file
·36 lines (31 loc) · 1.14 KB
/
eth2csv.py
File metadata and controls
executable file
·36 lines (31 loc) · 1.14 KB
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
if not len(sys.argv) == 2:
print("USAGE: "+sys.argv[0]+" candata.cap")
print("outputs CSV file for SavvyCAN to stdout")
sys.exit(1)
capFile = open(sys.argv[1],'r')
startTime = 0 # savvyCAN does not use unixtime
print('Time Stamp,ID,Extended,Dir,Bus,LEN,D1,D2,D3,D4,D5,D6,D7,D8')
pcap = dpkt.pcap.Reader(capFile)
for ts, buf in pcap:
if startTime == 0:
startTime = ts
microSeconds = int((ts - startTime) * 1000000.0)
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 = '0000'+packet[20:24]
message_data = packet[24:]
message_length = len(packet[24:]) / 2 # half the number number of hex characters
message_csv = ''
for i in range(message_length):
message_csv += message_data[i:i+2]+','
print(str(microSeconds)+','+message_id+',false,Rx,0,'+str(message_length)+','+message_csv.upper())
else:
print "x"
else:
print "x"