Strangle: DNS parsing for Python based on BIND
Strangle is BIND for Python: a Python library for parsing DNS messages using libbind. Strangle allows you to see DNS messages in two ways:
- Direct access to the libbind parsing functions (C-style)
- A Python object with various meaningful attributes (OO-style)
API Reference
- The libbind interface is a relatively direct wrapper around the ISC libbind routines.
- Strangle is a Pythonic, object-oriented parsing library for mere mortals.
Demo
Here is an example of how simple it is to parse DNS messages:
>>> 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 >>> msg.flags.type ‘question’ >>> msg.flags.recursionDesired True
Strangle is a fork of the unmaintained Constrict library, written by the same author at his previous organization. It is available under the GNU General Public License version 2.
If you have questions or comments about the software, feel free to contact us.
Download
Version 0.3.0 is available as a source tarball: Strangle-0.3.0.tar.gz
You can check out the Bazaar tree like so:
$ bzr branch http://www.proven-corporation.com/~jhs/Strangle.bzr/
Installation
Currently, Strangle is known to work with Python 2.3 through 2.5 on the major Linux distributions and Solaris. Strangle is a standard distutils-driven Python package. It also has a C language component that must be compiled against the BIND parsing library (libbind). For Debian-based distributions (including Ubuntu), you need the “bind-dev” package, as well as standard C development packages (gcc, libc6-dev, etc.). For RPM-based distributions, you need “bind-devel”.
- Install the BIND development package. For Debian, this is “bind-dev”. For Solaris, install from http://www.sunfreeware.com. Note, since the library is linked in statically, you may safely remove the package after installing Strangle.
- Uncompress the archive that you have downloaded. By default, it will extract to a directory named Strangle-
. - Change to that directory and run the install command:
- python setup.py install
- Everything should compile properly and you should be able to use the Strangle library from any location in your system.
>>> import Strangle >>> Strangle
