Implementation of the configuration object.

class scapy.config.CacheInstance(name: str = 'noname', timeout: Optional[int] = None)[source]

Bases: Dict[str, Any], object

copy() CacheInstance[source]
flush() None[source]
get(item: str, default: Optional[Any] = None) Any[source]
items() Any[source]
iteritems() Iterator[Tuple[str, Any]][source]
iterkeys() Iterator[str][source]
itervalues() Iterator[Tuple[str, Any]][source]
keys() Any[source]
summary() str[source]
update(other: Any, **kwargs: Any) None[source]
values() Any[source]
class scapy.config.CommandsList(iterable=(), /)[source]

Bases: List[Callable[[…], Any]]

register(cmd: DecoratorCallable) DecoratorCallable[source]
class scapy.config.Conf[source]

Bases: ConfClass

This object contains the configuration of Scapy.

ASN1_default_codec: scapy.asn1.asn1.ASN1Codec = None

Codec used by default for ASN1 objects

AS_resolver: scapy.as_resolvers.AS_resolver = None

choose the AS resolver class to use

BTsocket: Type[scapy.supersocket.SuperSocket] = None
L2listen: Type[scapy.supersocket.SuperSocket] = None
L2socket: Type[scapy.supersocket.SuperSocket] = None
L3socket: Type[scapy.supersocket.SuperSocket] = None
L3socket6: Type[scapy.supersocket.SuperSocket] = None
USBsocket: Type[scapy.supersocket.SuperSocket] = None
auto_crop_tables = True
auto_fragment = True
bufsize = 65536
cache_pcapiflist: Dict[str, Tuple[str, List[str], Any, str]] = {}

holds the cache of interfaces loaded from Libpcap

checkIPID = False

if 0, doesn’t check that IPID matches between IP sent and ICMP IP citation received if 1, checks that they either are equal or byte swapped equals (bug in some IP stacks) if 2, strictly checks that they are equals

checkIPaddr = True
checkIPinIP = True

if True, checks that IP-in-IP layers match. If False, do not check IP layers that encapsulates another IP layer

checkIPsrc = True

if 1, checks IP src in IP and ICMP IP citation match (bug in some NAT stacks)

check_TCPerror_seqack = False

if 1, also check that TCP seq and ack match the ones in ICMP citation

commands: CommandsList = bind_layers           : Bind 2 layers on some specific fields' values. bridge_and_sniff      : Forward traffic between interfaces if1 and if2, sniff and return chexdump              : Build a per byte hexadecimal representation corrupt_bits          : Flip a given percentage (at least one bit) or number of bits corrupt_bytes         : Corrupt a given percentage (at least one byte) or number of bytes explore               : Function used to discover the Scapy layers and protocols. fletcher16_checkbytes : Calculates the Fletcher-16 checkbytes returned as 2 byte binary-string. fletcher16_checksum   : Calculates Fletcher-16 checksum of the given buffer. fuzz                  : Transform a layer into a fuzzy layer by replacing some default values hexdiff               : Show differences between 2 binary strings, Packets... hexdump               : Build a tcpdump like hexadecimal view hexedit               : Run hexedit on a list of packets, then return the edited packets. hexstr                : Build a fancy tcpdump like hex from bytes. import_hexcap         : Imports a tcpdump like hexadecimal view linehexdump           : Build an equivalent view of hexdump() on a single line ls                    : List  available layers, or infos on a given layer class or name. rderf                 : Read a ERF file and return a packet list rdpcap                : Read a pcap or pcapng file and return a packet list restart               : Restarts scapy rfc                   : Generate an RFC-like representation of a packet def. send                  : Send packets at layer 3 sendp                 : Send packets at layer 2 sendpfast             : Send packets at layer 2 using tcpreplay for performance sniff                 : Sniff packets and return a list of packets. split_layers          : Split 2 layers previously bound. sr                    : Send and receive packets at layer 3 sr1                   : Send packets at layer 3 and return only the first answer sr1flood              : Flood and receive packets at layer 3 and return only the first answer srflood               : Flood and receive packets at layer 3 srloop                : Send a packet at layer 3 in loop and print the answer each time srp                   : Send and receive packets at layer 2 srp1                  : Send and receive packets at layer 2 and return only the first answer srp1flood             : Flood and receive packets at layer 2 and return only the first answer srpflood              : Flood and receive packets at layer 2 srploop               : Send a packet at layer 2 in loop and print the answer each time tcpdump               : Run tcpdump or tshark on a list of packets. tdecode               : Run tshark on a list of packets. tshark                : Sniff packets and print them calling pkt.summary(). wireshark             : Runs Wireshark on a list of packets. wrerf                 : Write a list of packets to a ERF file wrpcap                : Write a list of packets to a pcap file wrpcapng              : Write a list of packets to a pcapng file
contribs: Dict[str, Any] = {}

a dict which can be used by contrib layers to store local configuration

crypto_valid = False
crypto_valid_advanced = False
debug_dissector = False

raise exception when a packet dissector raises an exception

debug_match = False

when 1, store received packet that are not matched into debug.recv

debug_tls = False

When 1, print some TLS session secrets when they are computed.

default_l2: Type[Packet] = None
dot15d4_protocol = None
emph = <Emphasize []>
except_filter = ''

BPF filter for packets to ignore

extensions_paths = '.'

path or list of paths where extensions are to be looked for

fancy_prompt = True
filter = ''

bpf filter added to every sniffing socket to exclude traffic from analysis

geoip_city = None
histfile = '/home/docs/.scapy_history'

history file

iface: 'scapy.interfaces.NetworkInterface'

selects the default output interface for srp() and sendp().

ifaces: scapy.interfaces.NetworkInterfaceDict = None

holds the Scapy interface list and manager

interactive = False
interactive_shell = ''



can be “ipython”, “python” or “auto”. Default

ipv6_enabled = True
layers = Packet              : <member 'name' of 'Packet' objects> NoPayload           : <member 'name' of 'Packet' objects> Raw                 : <member 'name' of 'Packet' objects> Padding             : <member 'name' of 'Packet' objects> ASN1_Packet         : <member 'name' of 'Packet' objects> ASN1_Packet         : <member 'name' of 'Packet' objects>
load_layers = ['bluetooth', 'bluetooth4LE', 'dcerpc', 'dhcp', 'dhcp6', 'dns', 'dot11', 'dot15d4', 'eap', 'gprs', 'hsrp', 'inet', 'inet6', 'ipsec', 'ir', 'isakmp', 'kerberos', 'l2', 'l2tp', 'ldap', 'llmnr', 'lltd', 'mgcp', 'mobileip', 'mspac', 'netbios', 'netflow', 'ntlm', 'ntp', 'ppi', 'ppp', 'pptp', 'radius', 'rip', 'rtp', 'sctp', 'sixlowpan', 'skinny', 'smb', 'smb2', 'smbclient', 'smbserver', 'snmp', 'tftp', 'vrrp', 'vxlan', 'x509', 'zigbee', 'tuntap']
loopback_name = 'lo'
manufdb: = None
mib: scapy.asn1.mib.MIBDict = None

holds MIB direct access dictionary

min_pkt_size = 60
neighbor: scapy.layers.l2.Neighbor = None
nmap_base: str = ''
nmap_kdb: Optional[NmapKnowledgeBase] = None
noenum = <Resolve []>

holds list of enum fields for which conversion to string should NOT be done

padding = 1

includes padding in disassembled packets

padding_layer: Type[Packet] = None
prog = display    = 'display' dot        = 'dot' hexedit    = 'hexer' ifconfig   = 'ifconfig' pdfreader  = 'xdg-open' psreader   = 'xdg-open' svgreader  = 'xdg-open' tcpdump    = 'tcpdump' tcpreplay  = 'tcpreplay' tshark     = 'tshark' universal_open = 'xdg-open' wireshark  = 'wireshark'
promisc = True

default mode for listening socket (to get answers if you spoof on a lan)

raise_no_dst_mac = False

When True, raise exception if no dst MAC found otherwise broadcast. Default is False.

raw_layer: Type[Packet] = None
raw_summary: Union[bool, Callable[[bytes], Any]] = False
recv_poll_rate = 0.05

how often to check for new packets. Defaults to 0.05s.

resolve = <Resolve []>

holds list of fields for which resolution should be done

route: scapy.route.Route = None

holds the Scapy IPv4 routing table and provides methods to manipulate it

route6: scapy.route6.Route6 = None

holds the Scapy IPv6 routing table and provides methods to manipulate it

session = ''

filename where the session will be saved

sniff_promisc: bool = True

default mode for sniff()

stats_classic_protocols: List[Type[Packet]] = []
stats_dot11_protocols: List[Type[Packet]] = []
stealth = 'not implemented'

if 1, prevents any unwanted packet to go out (ARP, DNS, …)

temp_files: List[str] = []
teredoPrefix: str = ''
teredoServerPort: int = None
use_npcap = False

use libpcap integration or not. Changing this value will update the conf.L[2/3] sockets


read only attribute to show if PyPy is in use

verb = 2

level of verbosity, from 0 (almost mute) to 3 (verbose)

warning_threshold = 5

how much time between warnings from the same place

wepkey = ''
class scapy.config.ConfClass[source]

Bases: object

configure(cnf: ConfClass) None[source]
class scapy.config.ConfigFieldList[source]

Bases: object

add(*flds: Any) None[source]
remove(*flds: Any) None[source]
class scapy.config.Emphasize[source]

Bases: ConfigFieldList

class scapy.config.Interceptor(name: str, default: Any, hook: Callable[[...], Any], args: Optional[List[Any]] = None, kargs: Optional[Dict[str, Any]] = None)[source]

Bases: object

static set_from_hook(obj: Conf, name: str, val: bool) None[source]
class scapy.config.LayersList[source]

Bases: List[Type[scapy.packet.Packet]]

filter(items: List[Type[Packet]]) None[source]

Disable dissection of unused layers to speed up dissection

layers() List[Tuple[str, str]][source]
register(layer: Type[Packet]) None[source]
unfilter() None[source]

Re-enable dissection for all layers

class scapy.config.NetCache[source]

Bases: object

add_cache(cache: CacheInstance) None[source]
flush() None[source]
new_cache(name: str, timeout: Optional[int] = None) CacheInstance[source]
update(other: NetCache) None[source]
class scapy.config.Num2Layer[source]

Bases: object

get(item: Union[int, Type[Packet]], default: Optional[Type[Packet]] = None) Optional[Union[int, Type[Packet]]][source]
register(num: int, layer: Type[Packet]) None[source]
register_layer2num(num: int, layer: Type[Packet]) None[source]
register_num2layer(num: int, layer: Type[Packet]) None[source]
class scapy.config.ProgPath[source]

Bases: ConfClass

display = 'display'
dot = 'dot'
hexedit = 'hexer'
ifconfig = 'ifconfig'
pdfreader = 'xdg-open'
psreader = 'xdg-open'
svgreader = 'xdg-open'
tcpdump = 'tcpdump'
tcpreplay = 'tcpreplay'
tshark = 'tshark'
universal_open = 'xdg-open'
wireshark = 'wireshark'
class scapy.config.Resolve[source]

Bases: ConfigFieldList

scapy.config.crypto_validator(func: DecoratorCallable) DecoratorCallable[source]

This a decorator to be used for any method relying on the cryptography library. # noqa: E501 Its behaviour depends on the ‘crypto_valid’ attribute of the global ‘conf’.

scapy.config.isCryptographyAdvanced() bool[source]

Check if the cryptography module is present, and if it supports X25519, ChaCha20Poly1305 and such.

Notes: - cryptography >= 2.0 is required - OpenSSL >= 1.1.0 is required

scapy.config.isCryptographyValid() bool[source]

Check if the cryptography module >= 2.0.0 is present. This is the minimum version for most usages in Scapy.

scapy.config.isPyPy() bool[source]

Returns either scapy is running under PyPy or not

scapy.config.lsc() None[source]

Displays Scapy’s default commands

scapy.config.scapy_delete_temp_files() None[source]