How to get CNAME with sockets ?
Sheila King
usenet at thinkspot.net
Sat Feb 16 22:41:12 EST 2002
On 17 Feb 2002 02:52:05 GMT, bokr at oz.net (Bengt Richter) wrote in
comp.lang.python in article <a4n5sl$9uj$0 at 216.39.172.122>:
> I don't know what you are really doing, but that sounds like
> systematically dialing all phone numbers in various area codes
> until you get Arnold Schwarzenegger ;-)
>
> Can't you get a copy of the 'phone directory and find him yourself?
> Or do you need to visit with all those others?
>
> Or is the metaphor totally inapplicable? ;-)
I don't think the metaphor is *totally* inapplicable, but I can see why
you would draw that conclusion without looking at the code.
Here is a snippet from the original Perl module:
==============(begin snippet)==============
BUILDLIST:
for ( "a".."z", "1..9999" ) {
my $query = $resolver->query ($_.'.'.$zone);
my $rr; next BUILDLIST unless $query;
foreach $rr ($query->answer) {
my $pushed = 0;
if ($rr->type eq "A") {
push @list, $rr->address;
$pushed = 1;
} elsif ($rr->type eq "CNAME") {
if ($rr->cname eq 'list.terminator') {
pop @list if $pushed;
last BUILDLIST;
} elsif ($rr->cname eq "skip") {
pop @list if $pushed;
next BUILDLIST;
}
}
}
============(end snippet)==================
It's more like, the hosts will be
a.zone
b.zone
c.zone
etc...
until there are no more hosts. The last host will have a CNAME that
resolves to list.terminator. I don't know WHY the original code adds
subdomains 1..9999 onto the list, since there are currently only TWO
razor servers that I can discover in the default zone, which is
razor.vipul.net
In my own Python adaptation, I did this:
===========(begin snippet)=================
subdomainlist = list(string.ascii_lowercase)
zone = 'razor.vipul.net'
host_IP_list =[]
response_times = {}
for subd in subdomainlist:
host = '%s.%s' % (subd, zone)
try:
IPaddy = socket.gethostbyname(host)
host_IP_list.append(IPaddy)
except socket.error, e:
pipe = os.popen('dnsquery -t CNAME %s' % host)
data = pipe.read()
if data.find('list.terminator') > -1:
break
===========(end snippet)=================
Notice that I left the 1..9999 off.
By the way, that isn't the complete translation of the razor-discover
client. Only a snip. And it isn't portable, either. Designed to work on
my web host with tools they have installed.
--
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