How to use perl to get lots of domans's IP address?

K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have lots of domains' name in a text file which called "in.txt".It looks like
that:

in.txt
www.yahoo.com
www.msn.com
www.aol.com
...


Now,I want to get their IP addresses,and put the results into a new text file
called "out.txt".It looks like:

out.txt
www.yahoo.com,66.94.230.51
www.baidu.com,202.108.250.249
www.sina.com.cn,61.135.152.77
www.sohu.com,61.135.150.75

How can I do that using Perl?Thanks in advance.

You can use Net::DNS, open the input file for reading, output
file for writing, loop over each line in the input, do the DNS
DNS query, and print to the output filehandle. If you have code
that's giving you trouble, you might consider posting it.

- --keith

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBCIkThVcNCxZ5ID8RAgHpAJ4ryti+wNOf00pXaB1bqbc+NJMJcACeMWwy
AEGTrkmwPfmbeOsoWEThwYg=
=/Npn
-----END PGP SIGNATURE-----
 
J

John W. Krahn

Facco said:
I have lots of domains' name in a text file which called "in.txt".It looks like
that:

in.txt
www.yahoo.com
www.msn.com
www.aol.com
...

Now,I want to get their IP addresses,and put the results into a new text file
called "out.txt".It looks like:

out.txt
www.yahoo.com,66.94.230.51
www.baidu.com,202.108.250.249
www.sina.com.cn,61.135.152.77
www.sohu.com,61.135.150.75

How can I do that using Perl?Thanks in advance.

This should do what you want:

#!/usr/bin/perl
use warnings;
use strict;
use Socket;

my $in_file = 'in.txt';
my $out_file = 'out.txt';

open my $in, '<', $in_file or die "Cannot open $in_file: $!";
open my $out, '>', $out_file or die "Cannot open $out_file: $!";

while ( <$in> ) {
chomp;
my $ip = gethostbyname $_;
print $out "$_,", inet_ntoa( $ip ), "\n" if defined $ip;
}

__END__



John
 
F

Facco Eloelo

Thank you very muc, John!
The script that you wrote is wonderful.

But there is a problem:
in fact,my "in.txt" contains nearly 1000 domains' names,
so,the time of the process is too long to wait.

Is there a good method to show the processing percent or the remaining time when
the script is runing?

thanks again!

--
 
A

Anno Siegel

Facco Eloelo said:
Thank you very muc, John!
The script that you wrote is wonderful.

But there is a problem:
in fact,my "in.txt" contains nearly 1000 domains' names,
so,the time of the process is too long to wait.

Is there a good method to show the processing percent or the remaining time when
the script is runing?

What have you tried to add that feature to John's solution?

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top