Extract fieldbus IO data from Wireshark capture files.
Project description
wireshark_fieldbus_io
Python package for extracting industrial fieldbus IO data packets from a Wireshark capture file.
It makes it easy to get the IO data between two specific devices on the fieldbus (e.g. PROFINET). After extracting, the data can be further analyzed using some Python code or in third party tools. For the latter the IO data can be exported as CSV file.
Some use cases:
- Interface development
- Troubleshooting
- Checking data consistency
This package uses pyshark for reading the Wireshark files.
Installation
You can install the package using pip:
pip install wireshark_fieldbus_io
Usage
Example for extracting the 436 byte IO data packets from a Wireshark file,
where the PROFINET data exchange between a PLC and a robot controller was captured.
from wireshark_fieldbus_io.packet_reader import IoPacketReader, Fieldbus
from wireshark_fieldbus_io.enums_types import Fieldbus
# Create the instance
wireshark_log = IoPacketReader()
# Settings
# Fieldbus selection
wireshark_log.fieldbus = Fieldbus.PROFINET
# MAC address of the first device (e.g. a PLC)
wireshark_log.mac_address_host = '01:02:03:04:05:06'
# MAC address of the other device (e.g. a robot controller)
wireshark_log.mac_address_partner = '51:52:53:54:55:56'
# Raw packet size (can be recognized in the Wireshark UI)
wireshark_log.raw_packet_size = 442
# IO packet size between the two devices (comes from your system configuration)
wireshark_log.io_packet_size = 436
# Device specific offsets (can be recognized in the Wireshark UI)
wireshark_log.offset_snd_packet = 5
wireshark_log.offset_rcv_packet = 4
# Process file
wireshark_log.read_file(
wireshark_file='my-wireshark-log.pcapng',
remove_duplicates=True, # removes subsequent packets with same IO data
# start_frame=500, # optional: filter packet range (start)
# end_frame=750 # optional: filter packet range (end)
)
# show result
print(
f'found {wireshark_log.nr_of_packets} packets'
f' ({wireshark_log.nr_of_snd_packets} packets sent,'
f' {wireshark_log.nr_of_rcv_packets} packets received)'
)
# Output:
# found 13289 packets (10521 packets sent, 2768 packets received)
Analyze packet data
Now you can work with the captured IO data packets:
# Print a part of the data from each packet (sent and received)
for pkt in wireshark_log.data_packets:
print(pkt.id, pkt.time, pkt.direction, len(pkt.bytes), pkt.bytes[1:4])
# Output (partial):
# 26318 2024-12-30 16:54:10.973099 snd 436 [7, 1, 180]
# 26319 2024-12-30 16:54:10.974128 rcv 436 [32, 0, 254]
# 26320 2024-12-30 16:54:10.974128 snd 436 [8, 1, 180]
Or do some decoding on the received packets:
# Some simple decoding function
def decode_input_data(bytes: list[int]) -> dict:
obj = {}
obj['var1'] = bytes[1]
obj['var2'] = bytes[435]
obj['same_val'] = obj['var1'] == obj['var2']
return obj
# Print the decoded data of each received packet
for pkt in wireshark_log.data_packets_rcv:
print(pkt.id, pkt.time, decode_input_data(pkt.bytes))
# Output (partial):
# 17924 2024-12-30 16:54:07.192184 {'var1': 32, 'var2': 32, 'same_val': True}
# 17928 2024-12-30 16:54:07.194178 {'var1': 80, 'var2': 80, 'same_val': True}
# 17936 2024-12-30 16:54:07.198175 {'var1': 16, 'var2': 16, 'same_val': True}
Export packet data
The data packets can be exported to .csv file using the export_csv function:
# Export the packet data as CSV file
wireshark_log.export_csv(f'my-profinet-packets.csv')
# Content of CSV file (partial):
pkt,time,direction,b0,b1,b2,b3,b4,[..]
26318,2024-12-30 16:54:10.973099,snd,35,7,1,180,1,[..]
26319,2024-12-30 16:54:10.974128,rcv,35,32,0,254,36,[..]
26320,2024-12-30 16:54:10.974128,snd,35,8,1,180,1,[..]
Known issues
- Send- and receive packet must have the same size.
- Processing larger files can take some time.
- Uses
pyshark's deprecateduse_jsoninstead of the recommendeduse_ek. - No input validation or error handling.
- EtherCAT not fully functional yet.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wireshark_fieldbus_io-0.2.0.tar.gz.
File metadata
- Download URL: wireshark_fieldbus_io-0.2.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
605409b711342e0c4f3d65b792015a93fcf225bb6228edb6dd9d73cb05e391c3
|
|
| MD5 |
dce2a443e8c60ffb31b7dd7dfe12b16a
|
|
| BLAKE2b-256 |
314101f52a8ab18974411fd42d503ac101732c994bd4e535d8fae2b68d111030
|
Provenance
The following attestation bundles were made for wireshark_fieldbus_io-0.2.0.tar.gz:
Publisher:
build.yml on mrBrutus/wireshark_fieldbus_io
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wireshark_fieldbus_io-0.2.0.tar.gz -
Subject digest:
605409b711342e0c4f3d65b792015a93fcf225bb6228edb6dd9d73cb05e391c3 - Sigstore transparency entry: 158766955
- Sigstore integration time:
-
Permalink:
mrBrutus/wireshark_fieldbus_io@41fab39da63d2cfacd52206474a0368a9955ebec -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/mrBrutus
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@41fab39da63d2cfacd52206474a0368a9955ebec -
Trigger Event:
push
-
Statement type:
File details
Details for the file wireshark_fieldbus_io-0.2.0-py3-none-any.whl.
File metadata
- Download URL: wireshark_fieldbus_io-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53ea549cf43209e81c25e975efdea2ca7c3f820c94191f6570fa5b8fc4b4c873
|
|
| MD5 |
f17e148e73ac802dcfbe84a4de057962
|
|
| BLAKE2b-256 |
5f89657ee08dc03cac9f5fc3876ad56c65b3813fe9b5599fe5cb7245bf986bfd
|
Provenance
The following attestation bundles were made for wireshark_fieldbus_io-0.2.0-py3-none-any.whl:
Publisher:
build.yml on mrBrutus/wireshark_fieldbus_io
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wireshark_fieldbus_io-0.2.0-py3-none-any.whl -
Subject digest:
53ea549cf43209e81c25e975efdea2ca7c3f820c94191f6570fa5b8fc4b4c873 - Sigstore transparency entry: 158766956
- Sigstore integration time:
-
Permalink:
mrBrutus/wireshark_fieldbus_io@41fab39da63d2cfacd52206474a0368a9955ebec -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/mrBrutus
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@41fab39da63d2cfacd52206474a0368a9955ebec -
Trigger Event:
push
-
Statement type: