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'')[源代码]

基类:Packet

aliastypes
answers(other)[源代码]
extract_padding(s)[源代码]
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)[源代码]
hashret()[源代码]
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='localnet', renewal_time=60, lease_time=1800)[源代码]

基类:AnsweringMachine

filter: str | None = 'udp and port 68 and port 67'
function_name = 'bootpd'
is_request(req)[源代码]
make_reply(req)[源代码]
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)[源代码]
参数:
  • 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)

print_reply(_, reply)[源代码]
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[源代码]

Send packets at layer 2

参数:
  • 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

返回:

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, max_count: int | None = None)[源代码]

基类:FieldListField

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

基类: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)[源代码]
getfield(pkt, s)[源代码]
i2m(pkt: Packet, x: str) bytes[源代码]
m2i(pkt: Packet, x: bytes) str[源代码]
randval()[源代码]
class scapy.layers.dhcp.DHCP(_pkt, /, *, options=b'')[源代码]

基类: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()[源代码]
class scapy.layers.dhcp.DHCPOptionsField(name: str, default: I | None, fmt: str = 'H', remain: int = 0)[源代码]

基类: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)[源代码]
i2m(pkt, x)[源代码]
i2repr(pkt, x)[源代码]
islist = 1
m2i(pkt, x)[源代码]
randval()[源代码]
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)[源代码]

基类:BOOTP_am

function_name = 'dhcpd'
make_reply(req)[源代码]
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[源代码]

基类:RandField

A RandValue for classless static routes

class scapy.layers.dhcp.RandDHCPOptions(size=None, rndstr=None)[源代码]

基类:RandField

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

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