scapy.layers.dns module

DNS: Domain Name System.

class scapy.layers.dns.DNS

Bases: scapy.packet.Packet

aliastypes = [<class 'scapy.layers.dns.DNS'>, <class 'scapy.packet.Packet'>]
answers(other)

DEV: true if self is an answer from other

compress()

Return the compressed DNS packet (using dns_compress()

fields_desc = [<scapy.fields.ConditionalField object>, <Field (DNS).id>, <Field (DNS).qr>, <Field (DNS).opcode>, <Field (DNS).aa>, <Field (DNS).tc>, <Field (DNS).rd>, <Field (DNS).ra>, <Field (DNS).z>, <Field (DNS).ad>, <Field (DNS).cd>, <Field (DNS).rcode>, <Field (DNS).qdcount>, <Field (DNS).ancount>, <Field (DNS).nscount>, <Field (DNS).arcount>, <Field (DNS).qd>, <Field (DNS).an>, <Field (DNS).ns>, <Field (DNS).ar>]
mysummary()

DEV: can be overloaded to return a string that summarizes the layer. Only one mysummary() is used in a whole packet summary: the one of the upper layer, # noqa: E501 except if a mysummary() also returns (as a couple) a list of layers whose # noqa: E501 mysummary() must be called if they are present.

post_build(pkt, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

class scapy.layers.dns.DNSQR(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns.InheritOriginDNSStrPacket

aliastypes = [<class 'scapy.layers.dns.DNSQR'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSQR).qname>, <Field (DNSQR).qtype>, <Field (DNSQR).qclass>]
show_indent = 0
class scapy.layers.dns.DNSQRField(name, countfld, passon=1)

Bases: scapy.layers.dns.DNSRRField

decodeRR(name, s, p)
class scapy.layers.dns.DNSRR(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns.InheritOriginDNSStrPacket

aliastypes = [<class 'scapy.layers.dns.DNSRR'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRR).rrname>, <Field (DNSRR).type>, <Field (DNSRR).rclass>, <Field (DNSRR).ttl>, <Field (DNSRR).rdlen>, <scapy.fields.MultipleTypeField object>]
show_indent = 0
class scapy.layers.dns.DNSRRCountField(name, default, rr)

Bases: scapy.fields.ShortField

i2h(pkt, x)

Convert internal value to human value

i2m(pkt, x)

Convert internal value to machine value

rr
class scapy.layers.dns.DNSRRDLV(*args, **kargs)

Bases: scapy.layers.dns.DNSRRDS

aliastypes = [<class 'scapy.layers.dns.DNSRRDLV'>, <class 'scapy.layers.dns.DNSRRDS'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRDS,DNSRRDLV).rrname>, <Field (DNSRRDS,DNSRRDLV).type>, <Field (DNSRRDS,DNSRRDLV).rclass>, <Field (DNSRRDS,DNSRRDLV).ttl>, <Field (DNSRRDS,DNSRRDLV).rdlen>, <Field (DNSRRDS,DNSRRDLV).keytag>, <Field (DNSRRDS,DNSRRDLV).algorithm>, <Field (DNSRRDS,DNSRRDLV).digesttype>, <Field (DNSRRDS,DNSRRDLV).digest>]
class scapy.layers.dns.DNSRRDNSKEY(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes = [<class 'scapy.layers.dns.DNSRRDNSKEY'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRDNSKEY).rrname>, <Field (DNSRRDNSKEY).type>, <Field (DNSRRDNSKEY).rclass>, <Field (DNSRRDNSKEY).ttl>, <Field (DNSRRDNSKEY).rdlen>, <Field (DNSRRDNSKEY).flags>, <Field (DNSRRDNSKEY).protocol>, <Field (DNSRRDNSKEY).algorithm>, <Field (DNSRRDNSKEY).publickey>]
class scapy.layers.dns.DNSRRDS(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes = [<class 'scapy.layers.dns.DNSRRDS'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRDS,DNSRRDLV).rrname>, <Field (DNSRRDS,DNSRRDLV).type>, <Field (DNSRRDS,DNSRRDLV).rclass>, <Field (DNSRRDS,DNSRRDLV).ttl>, <Field (DNSRRDS,DNSRRDLV).rdlen>, <Field (DNSRRDS,DNSRRDLV).keytag>, <Field (DNSRRDS,DNSRRDLV).algorithm>, <Field (DNSRRDS,DNSRRDLV).digesttype>, <Field (DNSRRDS,DNSRRDLV).digest>]
class scapy.layers.dns.DNSRRField(name, countfld, passon=1)

Bases: scapy.fields.StrField

countfld
decodeRR(name, s, p)
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.

holds_packets = 1
i2m(pkt, x)

Convert internal value to machine value

passon
class scapy.layers.dns.DNSRRMX(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes = [<class 'scapy.layers.dns.DNSRRMX'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRMX).rrname>, <Field (DNSRRMX).type>, <Field (DNSRRMX).rclass>, <Field (DNSRRMX).ttl>, <Field (DNSRRMX).rdlen>, <Field (DNSRRMX).preference>, <Field (DNSRRMX).exchange>]
class scapy.layers.dns.DNSRRNSEC(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes = [<class 'scapy.layers.dns.DNSRRNSEC'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRNSEC).rrname>, <Field (DNSRRNSEC).type>, <Field (DNSRRNSEC).rclass>, <Field (DNSRRNSEC).ttl>, <Field (DNSRRNSEC).rdlen>, <Field (DNSRRNSEC).nextname>, <Field (DNSRRNSEC).typebitmaps>]
class scapy.layers.dns.DNSRRNSEC3(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes = [<class 'scapy.layers.dns.DNSRRNSEC3'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRNSEC3).rrname>, <Field (DNSRRNSEC3).type>, <Field (DNSRRNSEC3).rclass>, <Field (DNSRRNSEC3).ttl>, <Field (DNSRRNSEC3).rdlen>, <Field (DNSRRNSEC3).hashalg>, <Field (DNSRRNSEC3).flags>, <Field (DNSRRNSEC3).iterations>, <Field (DNSRRNSEC3).saltlength>, <Field (DNSRRNSEC3).salt>, <Field (DNSRRNSEC3).hashlength>, <Field (DNSRRNSEC3).nexthashedownername>, <Field (DNSRRNSEC3).typebitmaps>]
class scapy.layers.dns.DNSRRNSEC3PARAM(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes = [<class 'scapy.layers.dns.DNSRRNSEC3PARAM'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRNSEC3PARAM).rrname>, <Field (DNSRRNSEC3PARAM).type>, <Field (DNSRRNSEC3PARAM).rclass>, <Field (DNSRRNSEC3PARAM).ttl>, <Field (DNSRRNSEC3PARAM).rdlen>, <Field (DNSRRNSEC3PARAM).hashalg>, <Field (DNSRRNSEC3PARAM).flags>, <Field (DNSRRNSEC3PARAM).iterations>, <Field (DNSRRNSEC3PARAM).saltlength>, <Field (DNSRRNSEC3PARAM).salt>]
class scapy.layers.dns.DNSRROPT(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns.InheritOriginDNSStrPacket

aliastypes = [<class 'scapy.layers.dns.DNSRROPT'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRROPT).rrname>, <Field (DNSRROPT).type>, <Field (DNSRROPT).rclass>, <Field (DNSRROPT).extrcode>, <Field (DNSRROPT).version>, <Field (DNSRROPT).z>, <Field (DNSRROPT).rdlen>, <Field (DNSRROPT).rdata>]
class scapy.layers.dns.DNSRRRSIG(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes = [<class 'scapy.layers.dns.DNSRRRSIG'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRRSIG).rrname>, <Field (DNSRRRSIG).type>, <Field (DNSRRRSIG).rclass>, <Field (DNSRRRSIG).ttl>, <Field (DNSRRRSIG).rdlen>, <Field (DNSRRRSIG).typecovered>, <Field (DNSRRRSIG).algorithm>, <Field (DNSRRRSIG).labels>, <Field (DNSRRRSIG).originalttl>, <Field (DNSRRRSIG).expiration>, <Field (DNSRRRSIG).inception>, <Field (DNSRRRSIG).keytag>, <Field (DNSRRRSIG).signersname>, <Field (DNSRRRSIG).signature>]
class scapy.layers.dns.DNSRRSOA(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes = [<class 'scapy.layers.dns.DNSRRSOA'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRSOA).rrname>, <Field (DNSRRSOA).type>, <Field (DNSRRSOA).rclass>, <Field (DNSRRSOA).ttl>, <Field (DNSRRSOA).rdlen>, <Field (DNSRRSOA).mname>, <Field (DNSRRSOA).rname>, <Field (DNSRRSOA).serial>, <Field (DNSRRSOA).refresh>, <Field (DNSRRSOA).retry>, <Field (DNSRRSOA).expire>, <Field (DNSRRSOA).minimum>]
class scapy.layers.dns.DNSRRSRV(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes = [<class 'scapy.layers.dns.DNSRRSRV'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRSRV).rrname>, <Field (DNSRRSRV).type>, <Field (DNSRRSRV).rclass>, <Field (DNSRRSRV).ttl>, <Field (DNSRRSRV).rdlen>, <Field (DNSRRSRV).priority>, <Field (DNSRRSRV).weight>, <Field (DNSRRSRV).port>, <Field (DNSRRSRV).target>]
class scapy.layers.dns.DNSRRTSIG(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes = [<class 'scapy.layers.dns.DNSRRTSIG'>, <class 'scapy.layers.dns._DNSRRdummy'>, <class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (DNSRRTSIG).rrname>, <Field (DNSRRTSIG).type>, <Field (DNSRRTSIG).rclass>, <Field (DNSRRTSIG).ttl>, <Field (DNSRRTSIG).rdlen>, <Field (DNSRRTSIG).algo_name>, <Field (DNSRRTSIG).time_signed>, <Field (DNSRRTSIG).fudge>, <Field (DNSRRTSIG).mac_len>, <Field (DNSRRTSIG).mac_data>, <Field (DNSRRTSIG).original_id>, <Field (DNSRRTSIG).error>, <Field (DNSRRTSIG).other_len>, <Field (DNSRRTSIG).other_data>]
class scapy.layers.dns.DNSStrField(name, default, fld=None, length_from=None, max_length=None)

Bases: scapy.fields.StrLenField

Special StrField that handles DNS encoding/decoding. It will also handle DNS decompression. (may be StrLenField if a length_from is passed),

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.

h2i(pkt, x)

Convert human value to internal value

i2len(pkt, x)

Convert internal value to a length usable by a FieldLenField

i2m(pkt, x)

Convert internal value to machine value

class scapy.layers.dns.DNSTextField(name, default, fld=None, length_from=None, max_length=None)

Bases: scapy.fields.StrLenField

Special StrLenField that handles DNS TEXT data (16)

any2i(pkt, x)

Try to understand the most input values possible and make an internal value from them

i2len(pkt, x)

Convert internal value to a length usable by a FieldLenField

i2m(pkt, s)

Convert internal value to machine value

islist = 1
m2i(pkt, s)

Convert machine value to internal value

class scapy.layers.dns.DNS_am(**kargs)

Bases: scapy.ansmachine.AnsweringMachine

filter = 'udp port 53'
function_name = 'dns_spoof'
is_request(req)
make_reply(req)
parse_options(joker='192.168.1.1', match=None)
scapy.layers.dns.DNSgetstr(*args, **kwargs)

Legacy function. Deprecated

class scapy.layers.dns.EDNS0TLV

Bases: scapy.packet.Packet

aliastypes = [<class 'scapy.layers.dns.EDNS0TLV'>, <class 'scapy.packet.Packet'>]
extract_padding(p)

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 (EDNS0TLV).optcode>, <Field (EDNS0TLV).optlen>, <Field (EDNS0TLV).optdata>]
class scapy.layers.dns.InheritOriginDNSStrPacket(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.packet.Packet

aliastypes = [<class 'scapy.layers.dns.InheritOriginDNSStrPacket'>, <class 'scapy.packet.Packet'>]
default_fields
direction
explicit
fields
fieldtype
name
original
overload_fields
overloaded_fields
packetfields
payload
post_transforms
raw_packet_cache
raw_packet_cache_fields
sent_time
sniffed_on
time
underlayer
wirelen
scapy.layers.dns.RRlist2bitmap(lst)

Encode a list of integers representing Resource Records to a bitmap field used in the NSEC Resource Record.

class scapy.layers.dns.RRlistField(name, default, fmt='H', remain=0)

Bases: scapy.fields.StrField

h2i(pkt, x)

Convert human value to internal value

i2repr(pkt, x)

Convert internal value to a nice representation

class scapy.layers.dns.TimeSignedField(name, default)

Bases: scapy.fields.StrFixedLenField

h2i(pkt, seconds)

Convert the number of seconds since 1-Jan-70 UTC to the packed representation.

i2h(pkt, packed_seconds)

Convert the internal representation to the number of seconds since 1-Jan-70 UTC.

i2repr(pkt, packed_seconds)

Convert the internal representation to a nice one using the RFC format.

scapy.layers.dns.bitmap2RRlist(bitmap)

Decode the ‘Type Bit Maps’ field of the NSEC Resource Record into an integer list.

scapy.layers.dns.dns_compress(pkt)

This function compresses a DNS packet according to compression rules.

scapy.layers.dns.dns_encode(x, check_built=False)

Encodes a bytes string into the DNS format

Parameters:
  • x – the string
  • check_built – detect already-built strings and ignore them
Returns:

the encoded bytes string

scapy.layers.dns.dns_get_str(s, pointer=0, pkt=None, _fullpacket=False)

This function decompresses a string s, starting from the given pointer.

Parameters:
  • s – the string to decompress
  • pointer – first pointer on the string (default: 0)
  • pkt – (optional) an InheritOriginDNSStrPacket packet
Returns:

(decoded_string, end_index, left_string)

scapy.layers.dns.dyndns_add(nameserver, name, rdata, type='A', ttl=10)

Send a DNS add message to a nameserver for “name” to have a new “rdata” dyndns_add(nameserver, name, rdata, type=”A”, ttl=10) -> result code (0=ok)

example: dyndns_add(“ns1.toto.com”, “dyn.toto.com”, “127.0.0.1”) RFC2136

scapy.layers.dns.dyndns_del(nameserver, name, type='ALL', ttl=10)

Send a DNS delete message to a nameserver for “name” dyndns_del(nameserver, name, type=”ANY”, ttl=10) -> result code (0=ok)

example: dyndns_del(“ns1.toto.com”, “dyn.toto.com”) RFC2136

scapy.layers.dns.isdnssecRR(obj)