goodness0001
05-05-2002, 01:20 AM
How would you go about creating a script that woudl read in text in the format of:
domain.com
domain.com
domain.com
Then run a test for each domain.com and insert its IP address into the database.
goodness0001
05-31-2002, 09:01 PM
i guess nobody knows how to do that.
weeps
05-31-2002, 09:20 PM
$fil = file("./domains.txt");
$j = count($fil);
for($i=0; $i<$j; $i++) {
$domain = "www." . $fil[$i];
$ip = gethostbyname($domain);
// insert into your database here
}
goodness0001
06-01-2002, 09:59 PM
Yeah it looks like it takes the domains from the file and then associates them with an IP as it resolves...correct?
Shyne
06-02-2002, 12:59 AM
The code that kdghsu made doesn't do what you want. You gotta be more specific of what you want, and what do you want to do with it and how to use it.
blacknight
06-02-2002, 11:30 AM
What exactly are you trying to accomplish?
If you gave more details somebody might be able to give you a more precise reply, though the code supplied probably does what you want (?)
goodness0001
06-13-2002, 05:33 PM
I want to take a text file that has domains such as:
domain.com
domain.net
domain.org
mydomain.com
andso-on.com
and have the script either write to a database or another text file that would also include the IP address that it resolves to such as
domain.com 10.10.10.10
domain.net 12.15.111.10
etc.
Matt Lightner
06-13-2002, 07:44 PM
Here you go:
#!/usr/bin/perl
use Socket;
# Edit these to point to your files...
my $infile = 'file.in';
my $outfle = 'file.out';
open(IN, "$infile") || die "Can't load domain file: $!\n";
open(OUT, ">>$outfile") || die "Can't open output file for writing: $!\n";
while (<IN>) {
s/\s//g;
if ($_) {
my $addr = gethostbyname $_ ||
do { warn "Can't resolve ${_}\n"; next };
my $ip = inet_ntoa $addr;
print OUT "$_ $ip\n";
}
}
close IN;
close OUT;Note that this will append to your database file--not overwrite it.
goodness0001
06-13-2002, 09:06 PM
Thanks i am testing it right now, seems to be working.
goodness0001
06-13-2002, 09:26 PM
Is there a way that if it times out or doesnt resolve, that it just write the domains anyway stating something like "no IP" or something.
sorry, i dont know perl at all.
Matt Lightner
06-13-2002, 09:44 PM
#!/usr/bin/perl
use Socket;
# Edit these to point to your files...
my $infile = 'file.in';
my $outfle = 'file.out';
open(IN, "$infile") || die "Can't load domain file: $!\n";
open(OUT, ">>$outfile") || die "Can't open output file for writing: $!\n";
while (<IN> ) {
s/\s//g;
if ($_) {
my $addr = gethostbyname $_ ||
do { warn "Can't resolve ${_}\n";
print OUT "$_ noIP\n";
next };
my $ip = inet_ntoa $addr;
print OUT "$_ $ip\n";
}
}
close IN;
close OUT;