scapy.layers.l2

Classes and functions for layer 2 protocols.

class scapy.layers.l2.ARP(_pkt, /, *, hwtype=1, ptype=2048, hwlen=None, plen=None, op=1, hwsrc=None, psrc=None, hwdst=None, pdst=None)[source]

Bases: Packet

aliastypes
answers(other: Packet) int[source]
extract_padding(s: bytes) Tuple[bytes, bytes][source]
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             HWTYPE            |             PTYPE             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     HWLEN     |      PLEN     |               OP              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             HWSRC             |              PSRC             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             HWDST             |              PDST             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                             Fig. ARP                             
ARP fields

hwtype

XShortEnumField

1

ptype

XShortEnumField

2048

hwlen

FieldLenField

None

plen

FieldLenField

None

op

ShortEnumField

1

hwsrc

MultipleTypeField (SourceMACField, StrFixedLenField)

None

psrc

MultipleTypeField (SourceIPField, SourceIP6Field, StrFixedLenField)

None

hwdst

MultipleTypeField (MACField, StrFixedLenField)

None

pdst

MultipleTypeField (IPField, IP6Field, StrFixedLenField)

None

hashret() bytes[source]
mysummary() str[source]
route() Tuple[str | None, str | None, str | None][source]
class scapy.layers.l2.ARP_am(self, IP_addr=None, ARP_addr=None, from_ip=None)[source]

Bases: AnsweringMachine[Packet]

Fake ARP Relay Daemon (farpd)

example: To respond to an ARP request for 192.168.100 replying on the ingress interface:

farpd(IP_addr='192.168.1.100',ARP_addr='00:01:02:03:04:05')

To respond on a different interface add the interface parameter:

farpd(IP_addr='192.168.1.100',ARP_addr='00:01:02:03:04:05',iface='eth0')

To respond on ANY arp request on an interface with mac address ARP_addr:

farpd(ARP_addr='00:01:02:03:04:05',iface='eth1')

To respond on ANY arp request with my mac addr on the given interface:

farpd(iface='eth1')

Optional Args:

inter=<n>   Interval in seconds between ARP replies being sent
filter: str | None = 'arp'
function_name = 'farpd'
is_request(req: Packet) bool[source]
make_reply(req: Packet) Packet[source]
optam0: Dict[str, Any]
optam1: Dict[str, Any]
optam2: Dict[str, Any]
optsend: Dict[str, Any]
optsniff: Dict[str, Any]
parse_options(IP_addr: str | None = None, ARP_addr: str | None = None, from_ip: str | None = None) None[source]
print_reply(req: Packet, reply: Packet) None[source]
static send_function(x: List[Packet] | Packet | SetGen[Packet] | _PacketList[Packet], iface: NetworkInterface | str | None = None, iface_hint: str | None = None, socket: SuperSocket | None = None, **kargs: Any) PacketList | None[source]

Send packets at layer 2

Parameters:
  • x – the packets

  • inter – time (in s) between two packets (default 0)

  • loop – send packet indefinitely (default 0)

  • count – number of packets to send (default None=1)

  • verbose – verbose mode (default None=conf.verb)

  • realtime – check that a packet was sent before sending the next one

  • return_packets – return the sent packets

  • socket – the socket to use (default is conf.L3socket(kargs))

  • iface – the interface to send the packets on

  • monitor – (not on linux) send in monitor mode

Returns:

None

send_reply(reply: Packet, send_function: Any = None) None[source]
class scapy.layers.l2.ARPingResult(res=None, name='ARPing', stats=None)[source]

Bases: SndRcvList

show(*args: Any, **kwargs: Any) None[source]

Print the list of discovered MAC addresses.

class scapy.layers.l2.CookedLinux(_pkt, /, *, pkttype=0, lladdrtype=512, lladdrlen=0, src=b'', proto=2048)[source]

Bases: Packet

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            PKTTYPE            |           LLADDRTYPE          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           LLADDRLEN           |              SRC              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
|                                                               |
+                               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                               |             PROTO             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                         Fig. CookedLinux                         
CookedLinux fields

pkttype

ShortEnumField

0

lladdrtype

XShortField

512

lladdrlen

ShortField

0

src

StrFixedLenField

b''

proto

XShortEnumField

2048

payload_guess

Possible sublayers: CANFD, CAN, EAPOL, IP, IPv6, IrLAPHead, ARP, Dot1AD, Dot1AH, Dot1Q, Ether, LLC, PPPoED, PPPoE

class scapy.layers.l2.CookedLinuxV2(_pkt, /, *, proto=2048, reserved=0, ifindex=0, lladdrtype=512, pkttype=0, lladdrlen=0, src=b'')[source]

Bases: CookedLinux

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             PROTO             |            RESERVED           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            IFINDEX                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           LLADDRTYPE          |    PKTTYPE    |   LLADDRLEN   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              SRC                              |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                        Fig. CookedLinuxV2                        
CookedLinuxV2 fields

proto

XShortEnumField

2048

reserved

ShortField

0

ifindex

IntField

0

lladdrtype

XShortField

512

pkttype

ByteEnumField

0

lladdrlen

ByteField

0

src

StrFixedLenField

b''

class scapy.layers.l2.DestMACField(name: str)[source]

Bases: MACField

i2h(pkt: Packet | None, x: str | None) str[source]
i2m(pkt: Packet | None, x: str | None) bytes[source]
class scapy.layers.l2.Dot1AD(_pkt, /, *, prio=0, dei=0, vlan=1, type=0)[source]

Bases: Dot1Q

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PRIO|D|          VLAN         |              TYPE             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                           Fig. Dot1AD                            
Dot1AD fields

prio

BitField (3 bits)

0

dei

BitField (1 bit)

0

vlan

BitField (12 bits)

1

type

XShortEnumField

0

payload_guess

Possible sublayers: MACsec, Dot1AD, Dot1AH, Dot1Q

class scapy.layers.l2.Dot1AH(_pkt, /, *, prio=0, dei=0, nca=0, res1=0, res2=0, isid=0)[source]

Bases: Packet

aliastypes
answers(other: Packet) int[source]
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PRIO|D|N|R|RES|                      ISID                     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |
+-+-+-+-+-+-+-+-+

                           Fig. Dot1AH                            
Dot1AH fields

prio

BitField (3 bits)

0

dei

BitField (1 bit)

0

nca

BitField (1 bit)

0

res1

BitField (1 bit)

0

res2

BitField (2 bits)

0

isid

ThreeBytesField

0

mysummary() str[source]
payload_guess

Possible sublayers: Ether

class scapy.layers.l2.Dot1Q(_pkt, /, *, prio=0, dei=0, vlan=1, type=0)[source]

Bases: Packet

aliastypes
answers(other: Packet) int[source]
default_payload_class(pay: bytes) Type[Packet][source]
deprecated_fields: Dict[str, Tuple[str, str]] = {'id': ('dei', '2.5.0')}
extract_padding(s: bytes) Tuple[bytes, bytes | None][source]
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PRIO|D|          VLAN         |              TYPE             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                            Fig. Dot1Q                            
Dot1Q fields

prio

BitField (3 bits)

0

dei

BitField (1 bit)

0

vlan

BitField (12 bits)

1

type

XShortEnumField

0

mysummary() str[source]
payload_guess

Possible sublayers: EtherCat, LLDPDU, MACControl, MACsec, OAM, Dot1AD, Dot1AH

class scapy.layers.l2.Dot3(_pkt, /, *, dst=None, src=None, len=None)[source]

Bases: Packet

aliastypes
answers(other: Packet) int[source]
classmethod dispatch_hook(_pkt: Any | None = None, *args: Any, **kargs: Any) Type[Packet][source]
extract_padding(s: bytes) Tuple[bytes, bytes][source]
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              DST                              |
+                               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                               |              SRC              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|              LEN              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                            Fig. Dot3                             
Dot3 fields

dst

DestMACField

None

src

SourceMACField

None

len

LenField

None

mysummary() str[source]
payload_guess

Possible sublayers: LLC_GARP, LLC

class scapy.layers.l2.Ether(_pkt, /, *, dst=None, src=None, type=36864)[source]

Bases: Packet

aliastypes
answers(other: Packet) int[source]
classmethod dispatch_hook(_pkt: bytes | None = None, *args: Any, **kargs: Any) Type[Packet][source]
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              DST                              |
+                               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                               |              SRC              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|              TYPE             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                            Fig. Ether                            
Ether fields

dst

DestMACField

None

src

SourceMACField

None

type

XShortEnumField

36864

hashret() bytes[source]
mysummary() str[source]
payload_guess

Possible sublayers: AOE, EtherCat, HomePlugAV, IFE, LLDPDU, MACControl, MACsec, MPLS, NSH, ProfinetIO, GRH, SlowProtocol, EAPOL, IP, IPv6, ARP, Dot1AD, Dot1AH, Dot1Q, Ether, LLC, LLTD, PPP_ECP, PPP_IPCP, PPPoED, PPPoE, SixLoWPAN

class scapy.layers.l2.GRE(_pkt, /, *, chksum_present=0, routing_present=0, key_present=0, seqnum_present=0, strict_route_source=0, recursion_control=0, flags=0, version=0, proto=0, chksum=None, offset=None, key=None, sequence_number=None)[source]

Bases: Packet

aliastypes
deprecated_fields: Dict[str, Tuple[str, str]] = {'seqence_number': ('sequence_number', '2.4.4')}
classmethod dispatch_hook(_pkt: Any | None = None, *args: Any, **kargs: Any) Type[Packet][source]
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|C|R|K|S|S|RECUR|  FLAGS  |VERSI|             PROTO             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             CHKSUM            |             OFFSET            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              KEY                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        SEQUENCE NUMBER                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                             Fig. GRE                             
GRE fields

chksum_present

BitField (1 bit)

0

routing_present

BitField (1 bit)

0

key_present

BitField (1 bit)

0

seqnum_present

BitField (1 bit)

0

strict_route_source

BitField (1 bit)

0

recursion_control

BitField (3 bits)

0

flags

BitField (5 bits)

0

version

BitField (3 bits)

0

proto

XShortEnumField

0

chksum

XShortField (Cond)

None

offset

XShortField (Cond)

None

key

XIntField (Cond)

None

sequence_number

XIntField (Cond)

None

payload_guess

Possible sublayers: ERSPAN_III, ERSPAN_II, ERSPAN, MPLS, NSH, EAPOL, IP, IPv6, ARP, Dot1AD, Dot1AH, Dot1Q, Ether, GRErouting, LLC

post_build(p: bytes, pay: bytes) bytes[source]
class scapy.layers.l2.GRE_PPTP(_pkt, /, *, chksum_present=0, routing_present=0, key_present=1, seqnum_present=0, strict_route_source=0, recursion_control=0, acknum_present=0, flags=0, version=1, proto=34827, payload_len=None, call_id=None, sequence_number=None, ack_number=None)[source]

Bases: GRE

Enhanced GRE header used with PPTP RFC 2637

aliastypes
deprecated_fields: Dict[str, Tuple[str, str]] = {'seqence_number': ('sequence_number', '2.4.4')}
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|C|R|K|S|S|RECUR|A| FLAGS |VERSI|             PROTO             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          PAYLOAD LEN          |            CALL ID            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        SEQUENCE NUMBER                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           ACK NUMBER                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                          Fig. GRE_PPTP                           
GRE_PPTP fields

chksum_present

BitField (1 bit)

0

routing_present

BitField (1 bit)

0

key_present

BitField (1 bit)

1

seqnum_present

BitField (1 bit)

0

strict_route_source

BitField (1 bit)

0

recursion_control

BitField (3 bits)

0

acknum_present

BitField (1 bit)

0

flags

BitField (4 bits)

0

version

BitField (3 bits)

1

proto

XShortEnumField

34827

payload_len

ShortField

None

call_id

ShortField

None

sequence_number

XIntField (Cond)

None

ack_number

XIntField (Cond)

None

payload_guess

Possible sublayers: ERSPAN_III, ERSPAN_II, ERSPAN, EAPOL, IP, IPv6, ARP, Dot1AD, Dot1AH, Dot1Q, Ether, GRErouting, LLC, PPP

post_build(p: bytes, pay: bytes) bytes[source]
class scapy.layers.l2.GRErouting(_pkt, /, *, address_family=0, SRE_offset=0, SRE_len=None, routing_info=b'')[source]

Bases: Packet

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         ADDRESS FAMILY        |   SRE OFFSET  |    SRE LEN    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          ROUTING INFO         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                         Fig. GRErouting                          
GRErouting fields

address_family

ShortField

0

SRE_offset

ByteField

0

SRE_len

FieldLenField

None

routing_info

StrLenField

b''

payload_guess

Possible sublayers: GRErouting, Raw

class scapy.layers.l2.LLC(_pkt, /, *, dsap=0, ssap=0, ctrl=0)[source]

Bases: Packet

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      DSAP     |      SSAP     |      CTRL     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                             Fig. LLC                             
LLC fields

dsap

XByteField

0

ssap

XByteField

0

ctrl

ByteField

0

payload_guess

Possible sublayers: _create_cln_pdu, SNAP, STP

class scapy.layers.l2.LoIntEnumField(name: str, default: int | None, enum: Dict[int, str])[source]

Bases: IntEnumField

i2m(pkt: Packet | None, x: List[int] | int | None) int[source]
m2i(pkt: Packet | None, x: int) int[source]
class scapy.layers.l2.Loopback(_pkt, /, *, type=2)[source]

Bases: Packet

*BSD loopback layer

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              TYPE                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                          Fig. Loopback                           
Loopback fields

type

LoIntEnumField

2

payload_guess

Possible sublayers: IP, IPv6

class scapy.layers.l2.LoopbackOpenBSD(_pkt, /, *, type=2)[source]

Bases: Loopback

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              TYPE                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                       Fig. LoopbackOpenBSD                       
LoopbackOpenBSD fields

type

IntEnumField

2

class scapy.layers.l2.MPacketPreamble(_pkt, /, *, preamble=b'', fcs=0)[source]

Bases: Packet

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            PREAMBLE                           |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              FCS                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                       Fig. MPacketPreamble                       
MPacketPreamble fields

preamble

StrFixedLenField

b''

fcs

FCSField

0

payload_guess

Possible sublayers: Ether

class scapy.layers.l2.Neighbor[source]

Bases: object

register_l3(l2: Type[Packet], l3: Type[Packet], resolve_method: Callable[[Packet, Packet], str | None]) None[source]
resolve(l2inst: Packet, l3inst: Packet) str | None[source]
class scapy.layers.l2.SNAP(_pkt, /, *, OUI=0, code=0)[source]

Bases: Packet

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              OUI                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|              CODE             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                            Fig. SNAP                             
SNAP fields

OUI

OUIField

0

code

XShortEnumField

0

payload_guess

Possible sublayers: CDPv2_HDR, DTP, VTP, EAPOL, IP, IPv6, ARP, Dot1AD, Dot1AH, Dot1Q, Ether, STP

class scapy.layers.l2.STP(_pkt, /, *, proto=0, version=0, bpdutype=0, bpduflags=0, rootid=0, rootmac='00:00:00:00:00:00', pathcost=0, bridgeid=0, bridgemac='00:00:00:00:00:00', portid=0, age=1, maxage=20, hellotime=2, fwddelay=15)[source]

Bases: Packet

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             PROTO             |    VERSION    |    BPDUTYPE   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   BPDUFLAGS   |             ROOTID            |    ROOTMAC    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+               +
|                                                               |
+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |                    PATHCOST                   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |            BRIDGEID           |   BRIDGEMAC   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+               +
|                                                               |
+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |             PORTID            |      AGE      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |             MAXAGE            |   HELLOTIME   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |            FWDDELAY           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                             Fig. STP                             
STP fields

proto

ShortField

0

version

ByteField

0

bpdutype

ByteField

0

bpduflags

ByteField

0

rootid

ShortField

0

rootmac

MACField

'00:00:00:00:00:00'

pathcost

IntField

0

bridgeid

ShortField

0

bridgemac

MACField

'00:00:00:00:00:00'

portid

ShortField

0

age

BCDFloatField

1

maxage

BCDFloatField

20

hellotime

BCDFloatField

2

fwddelay

BCDFloatField

15

class scapy.layers.l2.SourceMACField(name: str, getif: Any | None = None)[source]

Bases: MACField

getif
i2h(pkt: Packet | None, x: str | None) str[source]
i2m(pkt: Packet | None, x: Any | None) bytes[source]
scapy.layers.l2.arp_mitm(ip1: str, ip2: str, mac1: List[str] | str | None = None, mac2: List[str] | str | None = None, broadcast: bool = False, target_mac: str | None = None, iface: NetworkInterface | str | None = None, inter: int = 3) None[source]

ARP MitM: poison 2 target’s ARP cache

Parameters:
  • ip1 – IPv4 of the first machine

  • ip2 – IPv4 of the second machine

  • mac1 – MAC of the first machine (optional: will ARP otherwise)

  • mac2 – MAC of the second machine (optional: will ARP otherwise)

  • broadcast – if True, will use broadcast mac for MitM by default

  • target_mac – MAC of the attacker (optional: default to the interface’s one)

  • iface – the network interface. (optional: default, route for ip1)

Example usage:

$ sysctl net.ipv4.conf.virbr0.send_redirects=0  # virbr0 = interface
$ sysctl net.ipv4.ip_forward=1
$ sudo scapy
>>> arp_mitm("192.168.122.156", "192.168.122.17")
Alternative usages:
>>> arp_mitm("10.0.0.1", "10.1.1.0/21", iface="eth1")
>>> arp_mitm("10.0.0.1", "10.1.1.2",
...          target_mac="aa:aa:aa:aa:aa:aa",
...          mac2="00:1e:eb:bf:c1:ab")

Warning

If using a subnet, this will first perform an arping, unless broadcast is on!

Remember to change the sysctl settings back..

scapy.layers.l2.arpcachepoison(target: str | List[str], addresses: str | Tuple[str, str] | List[Tuple[str, str]], broadcast: bool = False, count: int | None = None, interval: int = 15, **kwargs: Any) None[source]

Poison targets’ ARP cache

Parameters:
  • target – Can be an IP, subnet (string) or a list of IPs. This lists the IPs or the subnet that will be poisoned.

  • addresses – Can be either a string, a tuple of a list of tuples. If it’s a string, it’s the IP to advertise to the victim, with the local interface’s MAC. If it’s a tuple, it’s (“IP”, “MAC”). It it’s a list, it’s [(“IP”, “MAC”)]. “IP” can be a subnet of course.

  • broadcast – Use broadcast ethernet

Examples for target “192.168.0.2”:

>>> arpcachepoison("192.168.0.2", "192.168.0.1")
>>> arpcachepoison("192.168.0.1/24", "192.168.0.1")
>>> arpcachepoison(["192.168.0.2", "192.168.0.3"], "192.168.0.1")
>>> arpcachepoison("192.168.0.2", ("192.168.0.1", get_if_hwaddr("virbr0")))
>>> arpcachepoison("192.168.0.2", [("192.168.0.1", get_if_hwaddr("virbr0"),
...                                ("192.168.0.2", "aa:aa:aa:aa:aa:aa")])
scapy.layers.l2.arping(net: str, timeout: int = 2, cache: int = 0, verbose: int | None = None, **kargs: Any) Tuple[ARPingResult, PacketList][source]

Send ARP who-has requests to determine which hosts are up:

arping(net, [cache=0,] [iface=conf.iface,] [verbose=conf.verb]) -> None

Set cache=True if you want arping to modify internal ARP-Cache

scapy.layers.l2.arpleak(target: str, plen: int = 255, hwlen: int = 255, **kargs: Any) Tuple[SndRcvList, PacketList][source]

Exploit ARP leak flaws, like NetBSD-SA2017-002.

https://ftp.netbsd.org/pub/NetBSD/security/advisories/NetBSD-SA2017-002.txt.asc

scapy.layers.l2.etherleak(target: str, **kargs: Any) Tuple[SndRcvList, PacketList][source]

Exploit Etherleak flaw

scapy.layers.l2.getmacbyip(ip: str, chainCC: int = 0) str | None[source]

Return MAC address corresponding to a given IP address

scapy.layers.l2.is_promisc(ip: str, fake_bcast: str = 'ff:ff:00:00:00:00', **kargs: Any) bool[source]

Try to guess if target is in Promisc mode. The target is provided by its ip.

scapy.layers.l2.l2_register_l3(l2: Packet, l3: Packet) str | None[source]

Delegates resolving the default L2 destination address to the payload of L3.

scapy.layers.l2.l2_register_l3_arp(l2: Packet, l3: Packet) str | None[source]

Resolves the default L2 destination address when ARP is used.

scapy.layers.l2.promiscping(net: str, timeout: int = 2, fake_bcast: str = 'ff:ff:ff:ff:ff:fe', **kargs: Any) Tuple[ARPingResult, PacketList][source]

Send ARP who-has requests to determine which hosts are in promiscuous mode promiscping(net, iface=conf.iface)