SPUG: RE: DNS Lookups

Martin, Asa asa.martin at attws.com
Wed Feb 6 12:03:35 CST 2002


OK, I feel quite stupid now. Yes, there was a typo, sorry about that... and yes I should have said "use strict" because that would have caught it. If you replace the AF_NET with AF_INET it does indeed find the names for most of the IP addresses. However, if using this modified script, my nslookup program finds more names than gethostbyaddr:

#!/usr/local/bin/perl -w
# file: ip_trans.pl
use strict;
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_INET);
    my $nname = `nslookup $_ 2>/dev/null | grep Name: | awk '{print \$2}'`;
    chomp $nname;
    $name ||= '?';
    $nname ||= '?';
    print "$_ => $name\n";
    print "** $_ => $nname\n";
}

And, yes most of the IPs are probably caching servers. 

For example these IPs resolved with nslookup, but not with gethostbyaddr:
216.144.70.231
64.210.248.135
216.142.233.73
64.210.241.103
65.90.98.9
216.142.233.105
64.0.99.201

Asa

-----Original Message-----
From: Richard Anderson [mailto:richard at richard-anderson.org]
Sent: Wednesday, February 06, 2002 9:34 AM
To: Martin, Asa; spug-list at pm.org
Subject: Re: DNS Lookups


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





More information about the spug-list mailing list