#!/usr/bin/env perl use lib '/home/linuxutil'; use strict; use warnings; # use Net::Nslookup qw ( nslookup ); use LWP::UserAgent; use LWP::Protocol qw ( https ); use Term::ANSIColor qw ( BOLD BLUE RED GREEN RESET ); use Data::Dumper; ( my $WhoAmI = $0 ) =~ s{.*/}{}; use constant MaxTime1 => 20; # Seconds use constant MaxTime2 => 720; # Seconds use constant MaxTime3 => 3300; # Seconds use constant MaxTime4 => 6600; # Seconds use constant UNKNOWN => 0; # 0000b, unknown (default) use constant NO_UPDATE => 1; # 0001b, no update found use constant UPDATE => 2; # 0010b, update found use constant ERROR => 4; # 0100b, error use constant DOWNLOAD_FAIL => 8; # 1000b, unable to download my $FirefoxUserAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'; sub DownloadWebFile ( $$$$$$$$ ) { # Download the $Url's file and return the status my $IAm = ( caller(0) )[3]; # Incoming: my $Caller = "$_[0]" . "$IAm"; my $Host = $_[1]; # "download.fosshub.com"; my $UserAgent = $_[2]; # 'Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0' my $Referer = $_[3]; # "http://usa.kaspersky.com/windows10"; my $Cookies = $_[4]; # 'oraclelicense=accept-securebackup-cookie' my $Timeout = $_[5]; my $Url = $_[6]; my $FileName = $_[7]; # File name and path to save the file to # Outgoing: my $PageStatus = ""; $PageStatus = UPDATE; # 2 = good download my $ua; my $response; print "Downloading ", BOLD, BLUE, "$Url\n", RESET, "to ", BOLD, BLUE, "$FileName", RESET, "\n"; $ua = LWP::UserAgent->new; $ua->timeout ( MaxTime1 ); $ua->show_progress ( 1 ); # 0 = do not show; 1 = show $ua->agent('Mozilla/5.0'); $response = $ua->get( $Url, ':content_file' => "$FileName", 'Cookie' => "$Cookies", 'Referer' => "$Referer", 'User-Agent' => "$UserAgent", 'Host' => "$Host" ); # print STDERR "$content\n"; # if ( ! $response->is_success ) { # use Data::Dumper; # print Dumper($response); # ... # } if ( ! $response->is_success ) { $PageStatus = DOWNLOAD_FAIL; print STDERR BOLD RED " ERROR ${Caller}.GetWebPage: unable to read ", $Url, RESET, "\n"; print STDERR BOLD RED Dumper($response), RESET, "\n"; return ""; } } # curl --header 'Host: download.fosshub.com' http://www.fosshub.com/HWiNFO.html/hw64_554.exe -o eraseme # curl # # --header 'Host: download.fosshub.com' # # --header 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0' # # --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' # # --header 'Accept-Language: en-US,en;q=0.5' # # --header 'Referer: https://www.fosshub.com/HWiNFO.html/hw64_554.exe' # # --header 'Cookie: __cfduid=daf437999528d9d660b6cffb5aaccb5a21497412453' # # --header 'Connection: keep-alive' # # --header 'Upgrade-Insecure-Requests: 1' # # 'https://download.fosshub.com/Protected/expiretime=1500727489;badurl=aHR0cDovL3d3dy5mb3NzaHViLmNvbS9IV2lORk8uaHRtbA==/d7455c67933d1acd208e2b13e4dac1ab6691196a030c95de8a99af4630a91954/HWiNFO/hw64_554.exe' # # -o 'hw64_554.exe' -L # curl --header 'Referer: http://www.hwinfo.com/download.php' 'https://www.hwinfo.com/files/hw64_554.exe' -o 'hw64_554.exe' -L my $Status = DownloadWebFile( "HwINFO_Test ", "download.fosshub.com", "$FirefoxUserAgent", "https://www.fosshub.com/HWiNFO.html", "", MaxTime4, "https://www.fosshub.com/HWiNFO.html/hw64_554.exe", "eraseme" );