#!/usr/bin/perl
# #########################################################################
# Author: Valcho Nedelchev <kumcho@vulcho.com>
#
# Platform: Unix
#
# Language: Perl
#
# Description: Check domains whether have HTTP response or NOT.
#
# Usage: Create a file named weby.txt. Type domain names into and site
# title using PIPE '|' separator and use command:
# bash%> perl test_domains.pl
#
# #########################################################################
use LWP::Simple;
use strict;
my(@urls_ok, @urls_err, $i);
chomp(my @data=`cat weby.txt`);
for (@data) {
my @dd = split(/\|/, $_);
print " * ".$i++." * $dd[0] ...";
if (head("http://www.$dd[0]/")) {
print "[ok] - $dd[1]\n";
#print "INSERT INTO ext_links VALUES ('', '".quotemeta($dd[1])."', ".quotemeta("http://www.$dd[0]/")."');\n";
push @urls_ok, "INSERT INTO ext_links VALUES ('', '".quotemeta($dd[1])."', ".quotemeta("http://www.$dd[0]/")."');";
next;
}
if (head("http://www.$dd[0]/")) {
print "[ok] - $dd[1]\n";
#print "INSERT INTO ext_links VALUES ('', '".quotemeta($dd[1])."', ".quotemeta("http://$dd[0]/")."');\n";
push @urls_ok, "INSERT INTO ext_links VALUES ('', '".quotemeta($dd[1])."', ".quotemeta("http://$dd[0]/")."');";
next;
}
push @urls_err, $dd[0];
print "[ERROR]\n";
}
print "Writing ok-URLS [".scalar @urls_ok, "] in file...";
open OK, "> urls_ok.txt" or die "Cannot write to file: $!\n";
print OK join("\n", @urls_ok);
close OK;
print "[done]";
__END__