scapy.layers.can
A minimal implementation of the CANopen protocol, based on Wireshark dissectors. See https://wiki.wireshark.org/CANopen
- class scapy.layers.can.BEFloatSignalField(name: str, default: Union[int, float], start: int, scaling: Union[int, float] = 1, unit: str = '', offset: Union[int, float] = 0, ndigits: int = 3)[source]
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.BESignedSignalField(name: str, default: Union[int, float], start: int, size: int, scaling: Union[int, float] = 1, unit: str = '', offset: Union[int, float] = 0, ndigits: int = 3)[source]
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.BEUnsignedSignalField(name: str, default: Union[int, float], start: int, size: int, scaling: Union[int, float] = 1, unit: str = '', offset: Union[int, float] = 0, ndigits: int = 3)[source]
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.CAN(*args: Any, **kargs: Any)[source]
Bases:
scapy.packet.Packet
A minimal implementation of the CANopen protocol, based on Wireshark dissectors. See https://wiki.wireshark.org/CANopen
- aliastypes
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |FLAGS| IDENTIFIER | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | LENGTH | RESERVED | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | DATA | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. CAN
CAN fields flags
<Flag 0 ()>
identifier
XBitField
(29 bits)0
length
None
reserved
0
data
b''
- static inv_endianness(pkt: bytes) bytes [source]
Invert the order of the first four bytes of a CAN packet
This method is meant to be used specifically to convert a CAN packet between the pcap format and the socketCAN format
- Parameters
pkt – str of the CAN packet
- Returns
packet str with the first four bytes swapped
- class scapy.layers.can.CandumpReader(filename: str, interface: Optional[Union[List[str], str]] = None)[source]
Bases:
object
A stateful candump reader. Each packet is returned as a CAN packet
- dispatch(callback: Callable[[scapy.packet.Packet], None]) None [source]
call the specified callback routine for each packet read
This is just a convenience function for the main loop that allows for easy launching of packet processing in a thread.
- next() scapy.packet.Packet [source]
implement the iterator protocol on a set of packets
- nonblocking_socket = True
- static open(filename: Union[IO[bytes], str]) Tuple[str, Union[IO[bytes], gzip.GzipFile]] [source]
Open (if necessary) filename.
- read_all(count: int = - 1) scapy.plist.PacketList [source]
return a list of all packets in the candump file
- read_packet(size: int = 16) Optional[scapy.packet.Packet] [source]
return a single packet read from the file or None if filters apply
raise EOFError when no more packets are available
- recv(size: int = 16) Optional[scapy.packet.Packet] [source]
Emulate a socket
- static select(sockets: List[scapy.supersocket.SuperSocket], remain: Optional[int] = None) List[scapy.supersocket.SuperSocket] [source]
- class scapy.layers.can.LEFloatSignalField(name: str, default: Union[int, float], start: int, scaling: Union[int, float] = 1, unit: str = '', offset: Union[int, float] = 0, ndigits: int = 3)[source]
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.LESignedSignalField(name: str, default: Union[int, float], start: int, size: int, scaling: Union[int, float] = 1, unit: str = '', offset: Union[int, float] = 0, ndigits: int = 3)[source]
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.LEUnsignedSignalField(name: str, default: Union[int, float], start: int, size: int, scaling: Union[int, float] = 1, unit: str = '', offset: Union[int, float] = 0, ndigits: int = 3)[source]
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.SignalField(name: str, default: Union[int, float], start: int, size: int, scaling: Union[int, float] = 1, unit: str = '', offset: Union[int, float] = 0, ndigits: int = 3, fmt: str = 'B')[source]
Bases:
scapy.fields.ScalingField
- addfield(pkt: scapy.packet.Packet, s: bytes, val: Optional[Union[int, float]]) bytes [source]
- getfield(pkt: scapy.packet.Packet, s: bytes) Tuple[bytes, Union[int, float]] [source]
- i2len(pkt: scapy.packet.Packet, x: Any) int [source]
- randval() Union[scapy.volatile.RandBinFloat, scapy.volatile.RandFloat] [source]
- size
- start
- class scapy.layers.can.SignalHeader(*args: Any, **kargs: Any)[source]
Bases:
scapy.layers.can.CAN
- aliastypes
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |FLAGS| IDENTIFIER | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | LENGTH | RESERVED | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | +-+-+-+-+-+-+-+-+ Fig. SignalHeader
SignalHeader fields flags
<Flag 0 ()>
identifier
XBitField
(29 bits)0
length
None
reserved
0
- class scapy.layers.can.SignalPacket(*args: Any, **kargs: Any)[source]
Bases:
scapy.packet.Packet
- aliastypes
- scapy.layers.can.rdcandump(filename: str, count: int = - 1, interface: Union[None, str] = None) scapy.plist.PacketList [source]
Read a candump log file and return a packet list
filename: file to read count: read only <count> packets interfaces: return only packets from a specified interface