How to get CNAME with sockets ?

Sheila King usenet at thinkspot.net
Sat Feb 16 17:14:25 EST 2002


I'm working on using Vipul's Razor (http://razor.sourceforge.net) in
conjunction with a Python mail script that I'm working on.

I'm studying some of the Perl code (and I don't really know Perl...makes
it a bit tough). Anyhow, I've gathered that in the sub discover what I
basically need to do, is query each subdomain of razor.vipul.net where
the subdomains are a..z,1..9999 until I find one whose CNAME (or
Canonical Name) is last.terminator.

At this time, it appears that there are only two razor servers in the
zone razor.vipul.net (so far as I can tell).
a.razor.vipul.net = ubik.vipul.net = 194.109.217.74
-AND-
b.razor.vipul.net = adept.darkridge.com = 64.90.164.74

By using Sam Spade, I was able to see that c.razor.vipul.net has the
CNAME last.terminator, which is supposed to signal that I should stop
trying to "discover" new razor servers in the zone razor.vipul.net.

Now using the socket module for Python, I was able to find out all the
facts about a.razor.vipul.net and about b.razor.vipul.net by doing
something like this:

>>> socket.getfqdn('a.razor.vipul.net')
'ubik.vipul.net'
>>> socket.gethostbyaddr('ubik.vipul.net')
('ubik.vipul.net', ['a.razor.vipul.net'], ['194.109.217.74'])


But it appears that one cannot get the CNAME for c.razor.vipul.net using
the socket module. This requires a 3rd party application? I did find
this page
http://c0re.jp/c0de/dnsmodule/
which points to some python DNS modules. However, I only need this for
one line in my program, so I don't really want to import a module for
that. (I'm sharing this with other people and don't want to require them
to install additional packages.)

The machine I'm running this on does offer the command
dnsquery

and if I give the following instruction on the command line:
dnsquery -t CNAME c.razor.vipul.net

I get these results:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45010
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;;      c.razor.vipul.net, type = CNAME, class = IN
c.razor.vipul.net.      14m52s IN CNAME  list.terminator.

I can extract the string "list.terminator" from the reply.

I guess the best way to handle this is with a popen command? Like:

pipe = os.popen('dnsquery -t CNAME c.razor.vipul.net')
data = pipe.read()

If anyone has remarks, comments or suggestions, I'd be happy to hear
them. I wish I didn't have to rely on 3rd party apps for this, but it
appears Python doesn't have the built-in ability to get CNAME records in
the standard library?

-- 
Sheila King
http://www.thinkspot.net/sheila/

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_




More information about the Python-list mailing list