This script logs into to 3 routers in my network. Th script is working fine if all the 3 IP's (routers) are up and accessible. But if one of the routers is not accessible, then the for loop finish and the script ends, instead of hopping onto the next IP in the array.
I show you the output when i run the script with router 2 (192.168.2.1)disabled:
** GET http://192.168.1.1:80 ==> 401 Unauthorized (1s)
** GET http://192.168.1.1:80 ==> 200 OK
** GET http://192.168.2.1:80 ==> 404 Not Found (1s)
Error GETing http://192.168.2.1:80: Not Found at routerlogin.pl line 20.
login to 192.168.1.1:80 was successfull!!
The script should connect to router 3 (192.168.3.1) but neglects it after receiving a 404 <Not Found! I tried to edit the script like this but that doesn't work.
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize 1.73; my $file = "output.txt"; open (FH, "< $file") or die "Can't open $file for read: $!"; my @lines; while (<FH>) { push (@lines, $_); } close FH or die "Cannot close $file: $!"; chomp(@lines); for (my $i=0; $i <= @lines; $i++) { my $url = "$lines[$i]"; my $browser = WWW::Mechanize->new( autocheck => 1 ); $browser -> agent("Mozilla/5.0"); $browser -> timeout(10); $browser -> show_progress( 1 ); $browser -> credentials("$url",'TEL','admin' => 'guess'); $browser -> get("http://$url"); if($browser -> success){ print "login to $url was successfull!!"; } else{ print "login to $url was NOT successfull!!"; } }
After receiving the 404 <Not Found i want the script to print the text in the else clause: "login to $url was NOT successfull!!" and go further.
What am i missing here?
In reply to Re^4: perl cript logging into multiple routers
by xubu83
in thread perl script logging into multiple routers
by xubu83
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |