in reply to resolving ip's to names in a text file

You might want to look at Matching an IP address for the regex needed to match/grab the IP address, and then use Net::Whois to do the lookup.

Update:Net::DNS::RR::PTR is a better module for this, sleep helps you think better sometimes.
  • Comment on Re: resolving ip's to names in a text file

Replies are listed 'Best First'.
Re: Re: resolving ip's to names in a text file
by c (Hermit) on Jul 20, 2001 at 04:09 UTC
    I am not sure if Net::Whois is really what fits the case if he just wants to resolve an ip address to a dns entry. I think that Net::DNS::RR::PTR is more suitable.

    humbly -c

      I'm not sure of your input file but this should get you started in the right direction, if not maybe someone can learn a tip of two. HAVE FUN!
      #!/usr/bin/perl-w use strict; use win32; my $in_name=$ARGV[0]; my $out_name=$ARGV[1]; our (@x); # new type of global declaraton # carefull commas needed I.E. our (@x, @y); # use vars qw ( @x @y ); <- obsolete global declaration # pass a reminder if($#ARGV < 1) { die "usage: ip.pl <input file> <output file>\n" . "for example: program.pl infile.txt outfile.txt\n" } open(FILE, $in_name) || die "ip.pl can't open $in_name: $!"; open(IPFILE,">$out_name") || die "ip.pl can't open $out_name: $!"; my $dns2="toto"; #157.173.20.2 my $dns3="oz"; #157.173.20.3 my $dns4="wizard"; #157.173.20.4 my $ip2; my $ip3; my $ip4; while (<FILE>){ # sample line # Tz25,D,wizard,2,157.173.20.2,Local @x=split(/,/); next unless (($_ =~ /Local/)||($_ =~ /Network/)); if ($x[4] =~ /157.173.20.2/){ $ip2 = $dns2; print $x[0], $x[1], $x[2], $ip2; print IPFILE; } }
      That is exactly right. After doing a lookup on Net::Whois...i saw that that wasn't what i needed. I need to have it lookup the ip addresses in our local dns server. Thank you. ~Ray~
Re: Re: resolving ip's to names in a text file
by RayRay459 (Pilgrim) on Jul 20, 2001 at 03:52 UTC
    forgive me for sounding like a moron, but i am faily new to perl. How would i encorporate it into my script...the regex at least? ~Ray~
      Taking the regex out of RE: Matching an IP address, which is from the MRE book, with a few small modifications, came up with this.
      my @ips = ($string =~ m/((?:[01]?\d\d?|2[0-4]\d|25[0-5])\.(?:[01]?\d\d +?|2[0-4]\d|25[0-5])\.(?:[01]?\d\d?|2[0-4]\d|25[0-5])\.(?:[01]?\d\d?|2 +[0-4]\d|25[0-5]))/g);
      Now @ips will have an array full of IP's, if they are valid or not is another discussion...