mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-20 01:13:58 +00:00
feature: added pcapConverter to decode pcap logs
This commit is contained in:
parent
3b244ec3ca
commit
f50e99c753
2 changed files with 113987 additions and 0 deletions
45
pcapConverter.py
Normal file
45
pcapConverter.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
|
||||
# pcap Converter
|
||||
#
|
||||
# This little helper tool read a network trace (e.g. recorded with wireshark) and
|
||||
# interprets the content of the EXI.V2GTP.TCP.IPv6 data.
|
||||
#
|
||||
# Preconditions:
|
||||
# 1. You have a capture file with contains V2G traffic (pcap or pcapng file).
|
||||
# 2. You installed the python library pyshark, according to https://github.com/KimiNewt/pyshark/
|
||||
# pip install pyshark
|
||||
# 3. You cloned and compiled the OpenV2Gx EXI decoder from https://github.com/uhi22/OpenV2Gx
|
||||
|
||||
import pyshark
|
||||
import exiConnector
|
||||
|
||||
inputFileName = "efcaec23.pcap"
|
||||
cap = pyshark.FileCapture(inputFileName, display_filter="ipv6")
|
||||
fileOut = open(inputFileName + '.decoded.txt', 'w')
|
||||
#print(cap)
|
||||
#print(cap[0])
|
||||
#print(cap[1])
|
||||
#print(dir(cap[1]))
|
||||
#print(cap[1].sniff_time) # readable time
|
||||
#print(cap[1].sniff_timestamp) # epoch time
|
||||
numberOfPackets=0
|
||||
for packet in cap:
|
||||
numberOfPackets+=1
|
||||
#print(packet)
|
||||
if 'TCP' in packet:
|
||||
#print(packet.tcp.field_names)
|
||||
if ('payload' in packet.tcp.field_names):
|
||||
tcppayload = packet.tcp.payload # this gives a string of hex values, separated by ":", e.g. "01:fe:80:01"
|
||||
s = tcppayload.replace(":", "") # remove colons
|
||||
if (s[0:8]=="01fe8001"):
|
||||
# it is a V2GTP header with EXI content
|
||||
strExi = s[16:] # remove V2GTP header (8 bytes, means 16 hex characters)
|
||||
sHeader = "Packet #" + str(numberOfPackets) + " [" + str(packet.sniff_time) + "] " + strExi + " means:"
|
||||
pre = "DD" # decode DIN
|
||||
decoded=exiConnector.exiDecode(strExi, pre)
|
||||
print(sHeader)
|
||||
print(decoded)
|
||||
print(sHeader, file=fileOut)
|
||||
print(decoded, file=fileOut)
|
||||
fileOut.close()
|
||||
|
113942
results/2022-12-21_westpark_alpi_charge_ok_with_bulb.pcap.decoded.txt
Normal file
113942
results/2022-12-21_westpark_alpi_charge_ok_with_bulb.pcap.decoded.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue