Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
It may be easier to have just the domain name passed in to the script and then the script can handle ALL of the prefixes itself.

Yeah, that sounds sensible.
Here is an example of how you might implement that approach:

#!/usr/bin/perl use strict; use warnings; use LWP::Simple; DOMAIN: while (my $domain = <DATA>) { chomp($domain); for my $protocol (qw/http https/) { next DOMAIN if test_url("$protocol://$domain"); for my $sub (qw/www web/) { next DOMAIN if test_url("$protocol://$sub.$domain"); } } print "Couldn't get anything from $domain\n"; } sub test_url { my $url = shift; print "Trying $url ..."; my $ua = LWP::UserAgent->new( timeout => 5, agent => 'Mozilla/5.0', ssl_opts => { verify_hostname => 0 }, ); my $response = $ua->get($url); if ($response->is_success) { print "OK\n"; return 1; } else { print "FAILED because " . $response->status_line . "\n"; return undef; } } __DATA__ google.com apple.com fred.com dschjksdbckjqh.com
Output:
Trying http://google.com ...OK Trying http://apple.com ...OK Trying http://fred.com ...OK Trying http://dschjksdbckjqh.com ...FAILED because 500 Can't connect t +o dschjksdbckjqh.com:80 (Bad hostname 'dschjksdbckjqh.com') Trying http://www.dschjksdbckjqh.com ...FAILED because 500 Can't conne +ct to www.dschjksdbckjqh.com:80 (Bad hostname 'www.dschjksdbckjqh.com +') Trying http://web.dschjksdbckjqh.com ...FAILED because 500 Can't conne +ct to web.dschjksdbckjqh.com:80 (Bad hostname 'web.dschjksdbckjqh.com +') Trying https://dschjksdbckjqh.com ...FAILED because 500 Can't connect +to dschjksdbckjqh.com:443 (getaddrinfo: nodename nor servname provide +d, or not known) Trying https://www.dschjksdbckjqh.com ...FAILED because 500 Can't conn +ect to www.dschjksdbckjqh.com:443 (getaddrinfo: nodename nor servname + provided, or not known) Trying https://web.dschjksdbckjqh.com ...FAILED because 500 Can't conn +ect to web.dschjksdbckjqh.com:443 (getaddrinfo: nodename nor servname + provided, or not known) Couldn't get anything from dschjksdbckjqh.com

HTH,
Darren


In reply to Re^3: Unable to split $ARGV[0] variable. Can it be done? by McDarren
in thread [SOLVED]Unable to split $ARGV[0] variable. Can it be done? by Doozer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found