scapy.layers.dhcp module

DHCP (Dynamic Host Configuration Protocol) and BOOTP

Implements: - rfc951 - BOOTSTRAP PROTOCOL (BOOTP) - rfc1542 - Clarifications and Extensions for the Bootstrap Protocol - rfc1533 - DHCP Options and BOOTP Vendor Extensions

class scapy.layers.dhcp.BOOTP(_pkt, /, *, op=1, htype=1, hlen=6, hops=0, xid=0, secs=0, flags=<Flag 0 ()>, ciaddr='0.0.0.0', yiaddr='0.0.0.0', siaddr='0.0.0.0', giaddr='0.0.0.0', chaddr=b'', sname=b'', file=b'', options=b'')[source]

Bases: Packet

aliastypes
answers(other)[source]
extract_padding(s)[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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|       OP      |     HTYPE     |      HLEN     |      HOPS     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              XID                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|              SECS             |             FLAGS             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             CIADDR                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             YIADDR                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             SIADDR                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             GIADDR                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             CHADDR                            |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             SNAME                             |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              FILE                             |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            OPTIONS            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                            Fig. BOOTP                            
BOOTP fields

op

ByteEnumField

1

htype

ByteEnumField

1

hlen

ByteField

6

hops

ByteField

0

xid

XIntField

0

secs

ShortField

0

flags

FlagsField

<Flag 0 ()>

ciaddr

IPField

'0.0.0.0'

yiaddr

IPField

'0.0.0.0'

siaddr

IPField

'0.0.0.0'

giaddr

IPField

'0.0.0.0'

chaddr

_BOOTP_chaddr

b''

sname

StrFixedLenField

b''

file

StrFixedLenField

b''

options

StrEnumField

b''

guess_payload_class(payload)[source]
hashret()[source]
payload_guess

Possible sublayers: DHCP

class scapy.layers.dhcp.BOOTP_am(self, pool=Net('192.168.1.128/25'), network='192.168.1.0/24', gw='192.168.1.1', nameserver=None, domain=None, renewal_time=60, lease_time=1800, **kwargs)[source]

Bases: AnsweringMachine

filter: str | None = 'udp and port 68 and port 67'
function_name = 'bootpd'
is_request(req)[source]
make_reply(req)[source]
optam0: Dict[str, Any]
optam1: Dict[str, Any]
optam2: Dict[str, Any]
optsend: Dict[str, Any]
optsniff: Dict[str, Any]
parse_options(pool=Net('192.168.1.128/25'), network='192.168.1.0/24', gw='192.168.1.1', nameserver=None, domain=None, renewal_time=60, lease_time=1800, **kwargs)[source]
Parameters:
  • pool – the range of addresses to distribute. Can be a Net, a list of IPs or a string (always gives the same IP).

  • network – the subnet range

  • gw – the gateway IP (can be None)

  • nameserver – the DNS server IP (by default, same than gw)

  • domain – the domain to advertise (can be None)

Other DHCP parameters can be passed as kwargs. See DHCPOptions in dhcp.py. For instance:

dhcpd(pool=Net("10.0.10.0/24"), network="10.0.0.0/8", gw="10.0.10.1",
      classless_static_routes=["1.2.3.4/32:9.8.7.6"])
print_reply(_, reply)[source]
class scapy.layers.dhcp.ClasslessFieldListField(name: str, default: List[AnyField] | None, field: AnyField, length_from: Callable[[Packet], int] | None = None, count_from: Callable[[Packet], int] | None = None, max_count: int | None = None)[source]

Bases: FieldListField

randval()[source]
class scapy.layers.dhcp.ClasslessStaticRoutesField(name: str, default: Any, fmt: str = 'H')[source]

Bases: Field

RFC 3442 defines classless static routes as up to 9 bytes per entry:

# Code Len Destination 1 Router 1 +—–+—+—-+—–+—-+—-+—-+—-+—-+ | 121 | n | d1 | … | dN | r1 | r2 | r3 | r4 | +—–+—+—-+—–+—-+—-+—-+—-+—-+

Destination first byte contains one octet describing the width followed by all the significant octets of the subnet.

addfield(pkt, s, val)[source]
getfield(pkt, s)[source]
i2m(pkt: Packet, x: str) bytes[source]
m2i(pkt: Packet, x: bytes) str[source]
randval()[source]
class scapy.layers.dhcp.DHCP(_pkt, /, *, options=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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            OPTIONS            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                            Fig. DHCP                             
DHCP fields

options

DHCPOptionsField

b''

mysummary()[source]
class scapy.layers.dhcp.DHCPOptionsField(name: str, default: I | None, fmt: str = 'H', remain: int = 0)[source]

Bases: StrField

A field that builds and dissects DHCP options. The internal value is a list of tuples with the format [(“option_name”, <option_value>), …] Where expected names and values can be found using DHCPOptions

getfield(pkt, s)[source]
i2m(pkt, x)[source]
i2repr(pkt, x)[source]
islist = 1
m2i(pkt, x)[source]
randval()[source]
class scapy.layers.dhcp.DHCP_am(self, pool=Net('192.168.1.128/25'), network='192.168.1.0/24', gw='192.168.1.1', nameserver=None, domain=None, renewal_time=60, lease_time=1800, **kwargs)[source]

Bases: BOOTP_am

function_name = 'dhcpd'
make_reply(req)[source]
optam0: Dict[str, Any]
optam1: Dict[str, Any]
optam2: Dict[str, Any]
optsend: Dict[str, Any]
optsniff: Dict[str, Any]
class scapy.layers.dhcp.RandClasslessStaticRoutesField[source]

Bases: RandField

A RandValue for classless static routes

class scapy.layers.dhcp.RandDHCPOptions(size=None, rndstr=None)[source]

Bases: RandField

scapy.layers.dhcp.dhcp_request(hw=None, req_type='discover', server_id=None, requested_addr=None, hostname=None, iface=None, **kargs)[source]

Send a DHCP discover request and return the answer.

Usage:

>>> dhcp_request()  # send DHCP discover
>>> dhcp_request(req_type='request',
...              requested_addr='10.53.4.34')  # send DHCP request