summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-07-30 19:04:18 (GMT)
committerGuido van Rossum <guido@python.org>1996-07-30 19:04:18 (GMT)
commitef253701a6e502ce4b54ba9bc8e6c240c00ffd37 (patch)
treed59307361b6c9309e3ed627710e14c3e70eda7e8
parent29b1606951afd1190c2d0c25a9c71b816ac39369 (diff)
downloadcpython-ef253701a6e502ce4b54ba9bc8e6c240c00ffd37.zip
cpython-ef253701a6e502ce4b54ba9bc8e6c240c00ffd37.tar.gz
cpython-ef253701a6e502ce4b54ba9bc8e6c240c00ffd37.tar.bz2
print MX record
-rwxr-xr-xDemo/dns/asgethost.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Demo/dns/asgethost.py b/Demo/dns/asgethost.py
new file mode 100755
index 0000000..9a90268
--- /dev/null
+++ b/Demo/dns/asgethost.py
@@ -0,0 +1,35 @@
+import sys
+import dnslib
+import dnstype
+import dnsopcode
+import dnsclass
+import socket
+import select
+
+def main():
+ server = 'cnri.reston.va.us' # How?
+ port = 53
+ opcode = dnsopcode.QUERY
+ rd = 0
+ qtype = dnstype.MX
+ qname = sys.argv[1:] and sys.argv[1] or 'www.python.org'
+ m = dnslib.Mpacker()
+ m.addHeader(0,
+ 0, opcode, 0, 0, rd, 0, 0, 0,
+ 1, 0, 0, 0)
+ m.addQuestion(qname, qtype, dnsclass.IN)
+ request = m.getbuf()
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ s.connect((server, port))
+ s.send(request)
+ while 1:
+ r, w, x = [s], [], []
+ r, w, x = select.select(r, w, x, 0.333)
+ print r, w, x
+ if r:
+ reply = s.recv(1024)
+ u = dnslib.Munpacker(reply)
+ dnslib.dumpM(u)
+ break
+
+main()