Strangle API Reference

(Up to Strangle summary)

Strangle is an object with various attributes that describe the content of a DNS message. It is implemented with the lower-level libbind code.

Examining a Message

The common method of looking at a raw DNS message that you have is by making a DNSMessage object out of it. You can use a string or any file-like object.

>>> import Strangle
>>> msgFile = file(“test/data/www.microsoft.com-query”)
>>> msg = Strangle.DNSMessage(msgFile)
>>> msg.id
47096
>>> print msg
ID     : 47096
Headers:
  Type               : question
  Opcode             : 0
  Authoritative      : False
  Truncated          : False
  Recursion Desired  : True
  Recursion Available: False
  Response Code      : 0

;; QUESTION SECTION:
www.microsoft.com.nsatc.net 0       IN      A

Headers

You can see the message flags through the flags member object.

>>> msg.flags.type
‘question’
>>> msg.flags.recursionDesired
True

Message Sections

A DNSMessage has a sections member which is a dict. The keys are the sections of the message, as DNSSection objects. DNSSections are not very useful except for printing.

>>> msg = Strangle.DNSMessage(file(‘test/data/www.microsoft.com-response’))
>>> msg.sections.keys()
[‘answer’, ‘question’, ‘additional’, ‘authority’]
>>> sect = msg.sections[‘authority’]
>>> print sect

;; AUTHORITY SECTION:
nsatc.net               172800  IN      NS      j.ns.nsatc.net
nsatc.net               172800  IN      NS      k.ns.nsatc.net
nsatc.net               172800  IN      NS      us-ca-6.ns.nsatc.net
nsatc.net               172800  IN      NS      l.ns.nsatc.net

Data Records

DNSRecords are the final object, which usually live in a list.

>>> rec = sect.records2
>>> rec.ttl
172800
>>> rec.type
‘NS’