summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2005-09-02 05:21:28 +0000
committerBob Halley <halley@dnspython.org>2005-09-02 05:21:28 +0000
commitdf24d7e7fe18b2a4cd79c35d1c2efbb3e7ee5abc (patch)
tree3a987bc61f9847fb2d344d4d1fdbc56fa8f6bff9 /examples
parent2ed5e08d4485c5df41f6f2ef3b04148ef10af1cb (diff)
downloaddnspython-df24d7e7fe18b2a4cd79c35d1c2efbb3e7ee5abc.tar.gz
initial import
Original author: Bob Halley <halley@dnspython.org> Date: 2004-03-23 21:57:40
Diffstat (limited to 'examples')
-rw-r--r--examples/.arch-ids/=id1
-rw-r--r--examples/.arch-ids/mx.py.id1
-rw-r--r--examples/.arch-ids/name.py.id1
-rw-r--r--examples/.arch-ids/reverse.py.id1
-rw-r--r--examples/.arch-ids/xfr.py.id1
-rwxr-xr-xexamples/mx.py7
-rwxr-xr-xexamples/name.py13
-rwxr-xr-xexamples/reverse.py42
-rwxr-xr-xexamples/xfr.py10
9 files changed, 77 insertions, 0 deletions
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 <halley@dnspython.org> 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 <halley@dnspython.org> 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 <halley@dnspython.org> 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 <halley@dnspython.org> 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 <halley@dnspython.org> 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 <zone_filename>...
+#
+# 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)