SPUG: DNS Lookups

Ben Reser ben at reser.org
Wed Feb 6 11:49:39 CST 2002


On Wed, Feb 06, 2002 at 08:21:52AM -0800, Martin, Asa wrote:
> 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";
> }

AF_NET should be AF_INET

-- 
Ben Reser <ben at reser.org>
http://ben.reser.org

What difference does it make to the dead, the orphans, and the homeless,
whether the mad destruction is wrought under the name of totalitarianism
or the holy name of liberty and democracy? - Ghandi

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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