scapy.layers.tuntap

Implementation of TUN/TAP interfaces.

These allow Scapy to act as the remote side of a virtual network interface.

class scapy.layers.tuntap.DarwinUtunIfReq(_pkt, /, *, ctl_id=0, ctl_name=b'com.apple.net.utun_control')[source]

Bases: Packet

Structure for issuing Darwin ioctl commands (struct ctl_info).

See net/if_utun.h and sys/kern_control.h for reference.

aliastypes = [<class 'scapy.layers.tuntap.DarwinUtunIfReq'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<BitField (DarwinUtunIfReq).ctl_id>, <StrFixedLenField (DarwinUtunIfReq).ctl_name>]
class scapy.layers.tuntap.DarwinUtunPacketInfo(_pkt, /, *, addr_family=AddressFamily.AF_INET)[source]

Bases: Packet

aliastypes = [<class 'scapy.layers.tuntap.DarwinUtunPacketInfo'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (DarwinUtunPacketInfo).addr_family>]
payload_guess: List[Tuple[Dict[str, Any], Type[Packet]]] = [({'addr_family': AddressFamily.AF_INET}, <class 'scapy.layers.inet.IP'>), ({'addr_family': AddressFamily.AF_INET6}, <class 'scapy.layers.inet6.IPv6'>)]
class scapy.layers.tuntap.LinuxTunIfReq(_pkt, /, *, ifrn_name=b'', ifru_flags=0)[source]

Bases: Packet

Structure to request a specific device name for a tun/tap Linux struct ifreq.

See linux/if.h (struct ifreq) and tuntap.txt for reference.

aliastypes = [<class 'scapy.layers.tuntap.LinuxTunIfReq'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<StrFixedLenField (LinuxTunIfReq).ifrn_name>, <NativeShortField (LinuxTunIfReq).ifru_flags>]
class scapy.layers.tuntap.LinuxTunPacketInfo(_pkt, /, *, flags=<Flag 0 ()>, type=36864)[source]

Bases: TunPacketInfo

Base for TUN packets.

See linux/if_tun.h (struct tun_pi) for reference.

aliastypes = [<class 'scapy.layers.tuntap.LinuxTunPacketInfo'>, <class 'scapy.layers.tuntap.TunPacketInfo'>, <class 'scapy.layers.l2.Ether'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<FlagsField (LinuxTunPacketInfo).flags>, <XShortEnumField (LinuxTunPacketInfo).type>]
class scapy.layers.tuntap.NativeShortField(name, default)[source]

Bases: Field

class scapy.layers.tuntap.TunPacketInfo(_pkt, /)[source]

Bases: Packet

aliastypes = [<class 'scapy.layers.tuntap.TunPacketInfo'>, <class 'scapy.layers.l2.Ether'>]
class scapy.layers.tuntap.TunTapInterface(iface=None, mode_tun=None, default_read_size=65535, strip_packet_info=True, *args, **kwargs)[source]

Bases: SimpleSocket

A socket to act as the host’s peer of a tun / tap interface.

This implements kernel interfaces for tun and tap devices.

Parameters:
  • iface – The name of the interface to use, eg: ‘tun0’

  • mode_tun (bool) – If True, create as TUN interface (layer 3). If False, creates a TAP interface (layer 2). If not supplied, attempts to detect from the iface name.

  • strip_packet_info (bool) – If True (default), strips any TunPacketInfo from the packet. If False, leaves it in tact. Some operating systems and tunnel types don’t include this sort of data.

FreeBSD references:

Linux references:

desc = "Act as the host's peer of a tun / tap interface"
recv_raw(x=None)[source]
send(x: Packet) int[source]