LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-08-2005, 05:48 AM   #1
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Rep: Reputation: 34
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?
 
Old 12-08-2005, 07:38 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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;

Last edited by keefaz; 12-08-2005 at 07:56 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR The requested URL could not be retrieved While trying to retrieve the URL: /re Niceman2005 Linux - General 1 06-29-2005 09:51 AM
Use PHP URL processor script with Apache remi Linux - Networking 0 07-18-2004 01:44 PM
/etc/hosts resolving before DNS resolving ? markraem Linux - Networking 4 11-02-2003 04:54 AM
resolving host... soko Linux - Newbie 10 07-07-2002 10:50 AM
Resolving conflicts? Kage Linux - Software 0 01-27-2002 09:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration