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
- 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
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
_BOOTP_chaddr
b''
sname
b''
file
b''
options
b''
- 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'
- 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"])
- 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
- 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.
- class scapy.layers.dhcp.DHCP(_pkt, /, *, options=b'')[source]
Bases:
Packet
- aliastypes
- 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
- islist = 1
- 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'
- 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
- 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