Kaydet (Commit) 2559f5a7 authored tarafından Guido van Rossum's avatar Guido van Rossum

Removed Demo/dns -- see sf.net/projects/pydns/ instead.

üst 4a9ac4a8
This directory contains a module (dnslib) that implements a DNS
(Domain Name Server) client, plus additional modules that define some
symbolic constants used by DNS (dnstype, dnsclass, dnsopcode).
Type "python dnslib.py -/" for a usage message.
You can also import dnslib and write your own, more sophisticated
client code; use the test program as an example (there is currently no
documentation :-).
NOTE: This code has been evolved into a much more enhanced package by
Anthony Baxter; see the pydns project at SourceForge:
http://sourceforge.net/projects/pydns/
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()
# CLASS values (section 3.2.4)
IN = 1 # the Internet
CS = 2 # the CSNET class (Obsolete - used only for examples in
# some obsolete RFCs)
CH = 3 # the CHAOS class
HS = 4 # Hesiod [Dyer 87]
# QCLASS values (section 3.2.5)
ANY = 255 # any class
# Construct reverse mapping dictionary
_names = dir()
classmap = {}
for _name in _names:
if _name[0] != '_': classmap[eval(_name)] = _name
def classstr(klass):
if classmap.has_key(klass): return classmap[klass]
else: return `klass`
This diff is collapsed.
# Opcode values in message header (section 4.1.1)
QUERY = 0
IQUERY = 1
STATUS = 2
# Construct reverse mapping dictionary
_names = dir()
opcodemap = {}
for _name in _names:
if _name[0] != '_': opcodemap[eval(_name)] = _name
def opcodestr(opcode):
if opcodemap.has_key(opcode): return opcodemap[opcode]
else: return `opcode`
# TYPE values (section 3.2.2)
A = 1 # a host address
NS = 2 # an authoritative name server
MD = 3 # a mail destination (Obsolete - use MX)
MF = 4 # a mail forwarder (Obsolete - use MX)
CNAME = 5 # the canonical name for an alias
SOA = 6 # marks the start of a zone of authority
MB = 7 # a mailbox domain name (EXPERIMENTAL)
MG = 8 # a mail group member (EXPERIMENTAL)
MR = 9 # a mail rename domain name (EXPERIMENTAL)
NULL = 10 # a null RR (EXPERIMENTAL)
WKS = 11 # a well known service description
PTR = 12 # a domain name pointer
HINFO = 13 # host information
MINFO = 14 # mailbox or mail list information
MX = 15 # mail exchange
TXT = 16 # text strings
# Additional TYPE values from host.c source
UNAME = 110
MP = 240
# QTYPE values (section 3.2.3)
AXFR = 252 # A request for a transfer of an entire zone
MAILB = 253 # A request for mailbox-related records (MB, MG or MR)
MAILA = 254 # A request for mail agent RRs (Obsolete - see MX)
ANY = 255 # A request for all records
# Construct reverse mapping dictionary
_names = dir()
typemap = {}
for _name in _names:
if _name[0] != '_': typemap[eval(_name)] = _name
def typestr(type):
if typemap.has_key(type): return typemap[type]
else: return `type`
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment