Home|Personal|
Tutorials|Scripts|Stupid Tools

yaos°

 

»

Get.pl

 
 

#!/usr/bin/perl -w

use strict;
use Getopt::Std;

var_help() if (@ARGV == 0 || @ARGV == 1);

my (%options, $agent);
getopts('u:a:qt:n:p:hcr', \%options);
my $url = $options{'u'};

if ($options{'a'}) {
  $agent = $options{'a'};
} else { 
  $agent = 'http://www.yaos.de/perl/get/';
}

use LWP::Simple;
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
$ua->agent($agent);
$ua->proxy(['http', 'ftp'], $options{'p'}) if ($options{'p'});
$ua->timeout($options{'t'}) if ($options{'t'});

$options{'n'} = 1 if (!$options{'n'});
my $ntimes = $options{'n'}-1;

for(my $j=0;$j<=$ntimes;$j++) {

  my $req = HTTP::Request->new('GET', $url) if (!$options{'r'});
  $req = HTTP::Request->new('HEAD', $url) if ($options{'r'});
  my $response = $ua->request($req);

  if(!$options{'q'}) {
    if ($response->is_success()) {
      print ($response->headers_as_string(), "\n") if (!$options{'c'});;
      print ($response->content(), "\n") if (!$options{'h'});
    } else {
      print $response->message(), "\n";
    }
  }
}

sub var_help{
  print <<'  EOH';
usage: [-options] -u URL

Options are:
  -a agent, defines the User-Agent for Request-Header
  -q quiet, no output
  -t timeout, sets the timeout (in seconds)
  -h print only the Header
  -c print only the content
  -n Retrieve the document n times
  -p Proxy, use a proxy for connect
  -r use request method HEAD

Example:
  perl get.pl -u http://www.yaos.de/home/ -t 100 -a 'Example' > index.html
  Print the output into the File 'index.html'

  EOH
  exit(1);
}
      

© Henrik Teichmann

 

Valid HTML 4.01! Valid CSS!

Günstige Ersatzteile für Wäschetrockner beim Service-Center Emmel.
Erstklassiger Shop für Friseurbedarf.
Ferienhaus Dänemark - hier buchen.