From df24d7e7fe18b2a4cd79c35d1c2efbb3e7ee5abc Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Fri, 2 Sep 2005 05:21:28 +0000 Subject: initial import Original author: Bob Halley Date: 2004-03-23 21:57:40 --- examples/.arch-ids/=id | 1 + examples/.arch-ids/mx.py.id | 1 + examples/.arch-ids/name.py.id | 1 + examples/.arch-ids/reverse.py.id | 1 + examples/.arch-ids/xfr.py.id | 1 + examples/mx.py | 7 +++++++ examples/name.py | 13 +++++++++++++ examples/reverse.py | 42 ++++++++++++++++++++++++++++++++++++++++ examples/xfr.py | 10 ++++++++++ 9 files changed, 77 insertions(+) create mode 100644 examples/.arch-ids/=id create mode 100644 examples/.arch-ids/mx.py.id create mode 100644 examples/.arch-ids/name.py.id create mode 100644 examples/.arch-ids/reverse.py.id create mode 100644 examples/.arch-ids/xfr.py.id create mode 100755 examples/mx.py create mode 100755 examples/name.py create mode 100755 examples/reverse.py create mode 100755 examples/xfr.py (limited to 'examples') diff --git a/examples/.arch-ids/=id b/examples/.arch-ids/=id new file mode 100644 index 0000000..4ddde91 --- /dev/null +++ b/examples/.arch-ids/=id @@ -0,0 +1 @@ +Bob Halley Wed Mar 24 08:21:09 2004 4751.7 diff --git a/examples/.arch-ids/mx.py.id b/examples/.arch-ids/mx.py.id new file mode 100644 index 0000000..dd66337 --- /dev/null +++ b/examples/.arch-ids/mx.py.id @@ -0,0 +1 @@ +Bob Halley Wed Mar 24 08:22:59 2004 4771.0 diff --git a/examples/.arch-ids/name.py.id b/examples/.arch-ids/name.py.id new file mode 100644 index 0000000..11a3966 --- /dev/null +++ b/examples/.arch-ids/name.py.id @@ -0,0 +1 @@ +Bob Halley Wed Mar 24 08:22:59 2004 4771.1 diff --git a/examples/.arch-ids/reverse.py.id b/examples/.arch-ids/reverse.py.id new file mode 100644 index 0000000..ad99422 --- /dev/null +++ b/examples/.arch-ids/reverse.py.id @@ -0,0 +1 @@ +Bob Halley Wed Mar 24 08:22:59 2004 4771.2 diff --git a/examples/.arch-ids/xfr.py.id b/examples/.arch-ids/xfr.py.id new file mode 100644 index 0000000..6f7fd73 --- /dev/null +++ b/examples/.arch-ids/xfr.py.id @@ -0,0 +1 @@ +Bob Halley Wed Mar 24 08:22:59 2004 4771.3 diff --git a/examples/mx.py b/examples/mx.py new file mode 100755 index 0000000..3036e70 --- /dev/null +++ b/examples/mx.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +import dns.resolver + +answers = dns.resolver.query('nominum.com', 'MX') +for rdata in answers: + print 'Host', rdata.exchange, 'has preference', rdata.preference diff --git a/examples/name.py b/examples/name.py new file mode 100755 index 0000000..b099c49 --- /dev/null +++ b/examples/name.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +import dns.name + +n = dns.name.from_text('www.dnspython.org') +o = dns.name.from_text('dnspython.org') +print n.is_subdomain(o) # True +print n.is_superdomain(o) # False +print n > o # True +rel = n.relativize(o) # rel is the relative name www +n2 = rel + o +print n2 == n # True +print n.labels # ['www', 'dnspython', 'org', ''] diff --git a/examples/reverse.py b/examples/reverse.py new file mode 100755 index 0000000..47facc7 --- /dev/null +++ b/examples/reverse.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +# Usage: reverse.py ... +# +# This demo script will load in all of the zones specified by the +# filenames on the command line, find all the A RRs in them, and +# construct a reverse mapping table that maps each IP address used to +# the list of names mapping to that address. The table is then sorted +# nicely and printed. +# +# Note! The zone name is taken from the basename of the filename, so +# you must use filenames like "/wherever/you/like/dnspython.org" and +# not something like "/wherever/you/like/foo.db" (unless you're +# working with the ".db" GTLD, of course :)). +# +# If this weren't a demo script, there'd be a way of specifying the +# origin for each zone instead of constructing it from the filename. + +import dns.zone +import dns.ipv4 +import os.path +import sys + +reverse_map = {} + +for filename in sys.argv[1:]: + zone = dns.zone.from_file(filename, os.path.basename(filename), + relativize=False) + for (name, ttl, rdata) in zone.iterate_rdatas('A'): + l = reverse_map.get(rdata.address) + if l is None: + l = [] + reverse_map[rdata.address] = l + l.append(name) + +keys = reverse_map.keys() +keys.sort(lambda a1, a2: cmp(dns.ipv4.inet_aton(a1), dns.ipv4.inet_aton(a2))) +for k in keys: + v = reverse_map[k] + v.sort() + l = map(str, v) # convert names to strings for prettier output + print k, l diff --git a/examples/xfr.py b/examples/xfr.py new file mode 100755 index 0000000..5cd6f55 --- /dev/null +++ b/examples/xfr.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +import dns.query +import dns.zone + +z = dns.zone.from_xfr(dns.query.xfr('204.152.189.147', 'dnspython.org')) +names = z.nodes.keys() +names.sort() +for n in names: + print z[n].to_text(n) -- cgit v1.2.1