LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Resolving URL script (http://www.linuxquestions.org/questions/programming-9/resolving-url-script-390454/)

irfanhab 12-08-2005 05:48 AM

Resolving URL script
 
I have a list of URL's, I want to know which ones are valid, can someone write me a simple script in python or perl, which could tell me which sites are working (properly resolving) and which are not?

keefaz 12-08-2005 07:38 AM

Try (perl) :
Code:

#!/usr/bin/perl

use Socket;

# file where URLs are stored
my $file = '/path/to/url_file';

open URLS, "< $file" or die "Could not open $file: $!\n";

while (<URLS>) {
    chomp;
    next if /^$/;  # no need to test a blank line
    my $url = $_;
    s/http:\/\///;  # remove http:// from domaine name
    s/\/.*//;      # remove last / and URL path  if any

    if(gethostbyname $_) {
        print "$url is working\n";
    } else {
        print "$url is not working\n";
    }
}


close URLS;



All times are GMT -5. The time now is 03:25 PM.