scapy.layers.dhcp module

DHCP (Dynamic Host Configuration Protocol) and BOOTP

class scapy.layers.dhcp.BOOTP

Bases: scapy.packet.Packet

aliastypes = [<class 'scapy.layers.dhcp.BOOTP'>, <class 'scapy.packet.Packet'>]

DEV: true if self is an answer from other


DEV: to be overloaded to extract current layer’s padding.

Parameters:s (str) – the current layer
Returns:a couple of strings (actual layer, padding)
fields_desc = [<Field (BOOTP).op>, <Field (BOOTP).htype>, <Field (BOOTP).hlen>, <Field (BOOTP).hops>, <Field (BOOTP).xid>, <Field (BOOTP).secs>, <Field (BOOTP).flags>, <Field (BOOTP).ciaddr>, <Field (BOOTP).yiaddr>, <Field (BOOTP).siaddr>, <Field (BOOTP).giaddr>, <Field (BOOTP).chaddr>, <Field (BOOTP).sname>, <Field (BOOTP).file>, <Field (BOOTP).options>]

DEV: Guesses the next payload class from layer bonds. Can be overloaded to use a different mechanism.

Parameters:payload (str) – the layer’s payload
Returns:the payload class

DEV: returns a string that has the same value for a request and its answer.

payload_guess = [({'options': b'c\x82Sc'}, <class 'scapy.layers.dhcp.DHCP'>)]
class scapy.layers.dhcp.BOOTP_am(**kargs)

Bases: scapy.ansmachine.AnsweringMachine

filter = 'udp and port 68 and port 67'
function_name = 'bootpd'
parse_options(pool=Net(''), network='', gw='', domain='localnet', renewal_time=60, lease_time=1800)
print_reply(req, reply)
static send_function(x, inter=0, loop=0, iface=None, iface_hint=None, count=None, verbose=None, realtime=None, return_packets=False, socket=None, *args, **kargs)

Send packets at layer 2

  • x – the packets
  • inter – time (in s) between two packets (default 0)
  • loop – send packet indefinetly (default 0)
  • count – number of packets to send (default None=1)
  • verbose – verbose mode (default None=conf.verbose)
  • 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


class scapy.layers.dhcp.DHCP

Bases: scapy.packet.Packet

aliastypes = [<class 'scapy.layers.dhcp.DHCP'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DHCP).options>]
class scapy.layers.dhcp.DHCPOptionsField(name, default, fmt='H', remain=0)

Bases: scapy.fields.StrField

getfield(pkt, s)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

i2m(pkt, x)

Convert internal value to machine value

i2repr(pkt, x)

Convert internal value to a nice representation

islist = 1
m2i(pkt, x)

Convert machine value to internal value

class scapy.layers.dhcp.DHCP_am(**kargs)

Bases: scapy.layers.dhcp.BOOTP_am

function_name = 'dhcpd'
class scapy.layers.dhcp.RandDHCPOptions(size=None, rndstr=None)

Bases: scapy.volatile.RandField

scapy.layers.dhcp.dhcp_request(iface=None, **kargs)

Send a DHCP discover request and return the answer