scapy.layers.dns

DNS: Domain Name System.

class scapy.layers.dns.DNS

Bases: scapy.packet.Packet

aliastypes
answers(other)
compress()

Return the compressed DNS packet (using dns_compress()

fields_desc
DNS fields

length

ShortField (Cond)

None

id

ShortField

0

qr

BitField (1 bit)

0

opcode

BitEnumField (4 bits)

0

aa

BitField (1 bit)

0

tc

BitField (1 bit)

0

rd

BitField (1 bit)

1

ra

BitField (1 bit)

0

z

BitField (1 bit)

0

ad

BitField (1 bit)

0

cd

BitField (1 bit)

0

rcode

BitEnumField (4 bits)

0

qdcount

DNSRRCountField

None

ancount

DNSRRCountField

None

nscount

DNSRRCountField

None

arcount

DNSRRCountField

None

qd

DNSQRField

None

an

DNSRRField

None

ns

DNSRRField

None

ar

DNSRRField

None

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

Bases: scapy.layers.dns.InheritOriginDNSStrPacket

aliastypes
fields_desc
DNSQR fields

qname

DNSStrField

b'www.example.com'

qtype

ShortEnumField

1

qclass

ShortEnumField

1

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
fields_desc
DNSRR fields

rrname

DNSStrField

b'.'

type

ShortEnumField

1

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

FieldLenField

None

rdata

MultipleTypeField

b''

show_indent = 0
class scapy.layers.dns.DNSRRCountField(name, default, rr)

Bases: scapy.fields.ShortField

i2h(pkt, x)
i2m(pkt, x)
rr
class scapy.layers.dns.DNSRRDLV(*args, **kargs)

Bases: scapy.layers.dns.DNSRRDS

aliastypes
fields_desc
DNSRRDLV fields

rrname

DNSStrField

b'.'

type

ShortEnumField

43

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

keytag

ShortField

0

algorithm

ByteEnumField

5

digesttype

ByteEnumField

5

digest

StrField

b''

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

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRDNSKEY fields

rrname

DNSStrField

b'.'

type

ShortEnumField

48

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

flags

FlagsField (16 bits)

<Flag 256 (Z)>

protocol

ByteField

3

algorithm

ByteEnumField

5

publickey

StrField

b''

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

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRDS fields

rrname

DNSStrField

b'.'

type

ShortEnumField

43

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

keytag

ShortField

0

algorithm

ByteEnumField

5

digesttype

ByteEnumField

5

digest

StrField

b''

class scapy.layers.dns.DNSRRField(name, countfld, passon=1)

Bases: scapy.fields.StrField

countfld
decodeRR(name, s, p)
getfield(pkt, s)
holds_packets = 1
i2m(pkt, x)
passon
class scapy.layers.dns.DNSRRMX(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRMX fields

rrname

DNSStrField

b'.'

type

ShortEnumField

6

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

preference

ShortField

0

exchange

DNSStrField

b'.'

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

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRNSEC fields

rrname

DNSStrField

b'.'

type

ShortEnumField

47

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

nextname

DNSStrField

b'.'

typebitmaps

RRlistField

b''

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

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRNSEC3 fields

rrname

DNSStrField

b'.'

type

ShortEnumField

50

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

hashalg

ByteField

0

flags

BitEnumField (8 bits)

0

iterations

ShortField

0

saltlength

FieldLenField

0

salt

StrLenField

b''

hashlength

FieldLenField

0

nexthashedownername

StrLenField

b''

typebitmaps

RRlistField

b''

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

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRNSEC3PARAM fields

rrname

DNSStrField

b'.'

type

ShortEnumField

51

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

hashalg

ByteField

0

flags

ByteField

0

iterations

ShortField

0

saltlength

FieldLenField

0

salt

StrLenField

b''

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

Bases: scapy.layers.dns.InheritOriginDNSStrPacket

aliastypes
fields_desc
DNSRROPT fields

rrname

DNSStrField

b'.'

type

ShortEnumField

41

rclass

ShortField

4096

extrcode

ByteField

0

version

ByteField

0

z

BitEnumField (16 bits)

32768

rdlen

FieldLenField

None

rdata

PacketListField

[]

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

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRRSIG fields

rrname

DNSStrField

b'.'

type

ShortEnumField

46

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

typecovered

ShortEnumField

1

algorithm

ByteEnumField

5

labels

ByteField

0

originalttl

IntField

0

expiration

UTCTimeField

0

inception

UTCTimeField

0

keytag

ShortField

0

signersname

DNSStrField

b'.'

signature

StrField

b''

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

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRSOA fields

rrname

DNSStrField

b'.'

type

ShortEnumField

6

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

mname

DNSStrField

b'.'

rname

DNSStrField

b'.'

serial

IntField

0

refresh

IntField

0

retry

IntField

0

expire

IntField

0

minimum

IntField

0

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

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRSRV fields

rrname

DNSStrField

b'.'

type

ShortEnumField

33

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

priority

ShortField

0

weight

ShortField

0

port

ShortField

0

target

DNSStrField

b'.'

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

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRTSIG fields

rrname

DNSStrField

b'.'

type

ShortEnumField

250

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

algo_name

DNSStrField

b'hmac-sha1'

time_signed

TimeSignedField

b'\x00\x00\x00\x00\x00\x00'

fudge

ShortField

0

mac_len

FieldLenField

20

mac_data

StrLenField

b''

original_id

ShortField

0

error

ShortField

0

other_len

FieldLenField

0

other_data

StrLenField

b''

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)
h2i(pkt, x)
i2len(pkt, x)
i2m(pkt, x)
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)
i2len(pkt, x)
i2m(pkt, s)
islist = 1
m2i(pkt, s)
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
extract_padding(p)
fields_desc
EDNS0TLV fields

optcode

ShortEnumField

0

optlen

FieldLenField

None

optdata

StrLenField

b''

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

Bases: scapy.packet.Packet

aliastypes
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)
i2repr(pkt, x)
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)