scapy.layers.dhcp
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
BOOTP fields 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='localnet', renewal_time=60, lease_time=1800)[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='localnet', renewal_time=60, lease_time=1800)[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)
- 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
- 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)[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='localnet', renewal_time=60, lease_time=1800)[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