xubu83 has asked for the wisdom of the Perl Monks concerning the following question:

I am learning Perl. At this time i am experimenting with Perl module LWP. I wrote a script that is able to login to my router. I want the script to notify me if the login to the router is succesfull, or not. Some suggestions?

I got this so far:

#!/usr/bin/perl -w use strict; use LWP; my $browser = LWP::UserAgent->new; $browser -> agent("RouterBot/1.1 "); $browser -> credentials('192.168.1.1','TEL','admin' => 'pass'); $browser -> timeout(10); print "Connecting to router:\t(192.168.1.1)\n";

Replies are listed 'Best First'.
Re: Perl LWP Router login
by Anonymous Monk on May 18, 2015 at 01:31 UTC

    That script does not login to your router -- it creates a LWP object, sets some options, prints something and ends

    If you make a successful http request, that is enough indication that you've logged in

    So the answer is make a request :)

    #!/usr/bin/perl -- use strict; use warnings; use WWW::Mechanize 1.73; my $browser = WWW::Mechanize->new( autocheck => 1 ); $browser -> agent("RouterBot/1.1 "); $browser -> credentials('192.168.1.1','TEL','admin' => 'pass'); $browser -> timeout(10); $browser->show_progress( 1 ); $browser->get('http://192.168.1.1'); if( $browser->success ){ die " we logged in game over"; }

    See WWW::Mechanize::Examples as WWW::Mechanize is a much easier to use version of LWP

    More tips learn about the internet,Web Programming: For Beginners, to get an overall picture of how the internet works, how tcp/ip, sockets, html, ajax, all fit together.

Re: Perl LWP Router login
by thomas895 (Deacon) on May 18, 2015 at 01:25 UTC

    What have you tried? It's just your router, it won't fire you if you screw something up (which I hope is not possible).

    -Thomas
    "Excuse me for butting in, but I'm interrupt-driven..."