SPUG: Re: DNS Lookups
Richard Anderson
richard at richard-anderson.org
Wed Feb 6 11:33:52 CST 2002
Is there a typo in the gethostbyaddr call? The Programming Perl book gives
a similar example using AF_INET for the second parameter.
Also, I notice that most of the addresses you are having problems with are
cache servers. Coincidence?
Cheers,
Richard
richard at richard-anderson.org
www.richard-anderson.org
www.raycosoft.com
----- Original Message -----
From: "Martin, Asa" <asa.martin at attws.com>
To: <spug-list at pm.org>
Sent: Wednesday, February 06, 2002 8:21 AM
Subject: SPUG: DNS Lookups
> Here's something I've been wondering about for a while. Why is
gethostbyname not able to resolve many addresses, when my nslookup program
(on both my Solaris 2.8 box and Windows 2000) can? For example, I often have
to write scripts that convert between IP addresses and DNS names. Currently
I just run calls to nslookup and parse the results. I don't like that method
because it's not very platform independent. I found this script in the book
"Network Programming with Perl":
>
> #!/usr/local/bin/perl
> # file: ip_trans.pl
> use Socket;
> my $ADDR_PAT = '^\d+\.\d+\.\d+\.\d+$';
> while (<>) {
> chomp;
> die "$_: Not a valid address" unless /$ADDR_PAT/o;
> my $name = gethostbyaddr(inet_aton($_),AF_NET);
> $name ||= '?';
> print "$_ => $name\n";
> }
>
> However, this script does not resolve many addresses. For example the
following list comes back with '?'
>
> 205.188.208.137
> 152.163.188.39
> 64.12.96.198
> 205.188.209.75
> 152.163.189.103
> 152.163.189.72
> 152.163.188.8
> 205.188.208.167
> 207.172.11.233
> 205.188.209.13
> 205.188.208.74
> 205.188.208.75
> 152.163.188.168
> 198.81.23.78
> 205.188.209.170
> 205.188.209.171
>
> Do I need to do something on my box to get the perl functions to work? Or
is nslookup doing something else that can't be done with perl.
>
> Thanks,
>
> Asa Martin
>
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
> Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
> For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
> Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
>
>
>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list