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

Hi, i wanted to configure a device using HTTP page. my http page is 192.168.1.1 i wanted to access this web page using Login name : admin, password : password. Also wanted to to change the DNS ip there on the html page. Wanted to achieve all this using perl script. Following is the script i am trying to use for the same.
-------------------------------------------------------- use HTTP::Request; use LWP::UserAgent; $req = HTTP::Request->new($httpRequestMethod => "http://192.168.1.1/") +; $ua=LWP::UserAgent->new; $response=$ua->request($req); sleep 10; $req->authorization_basic("admin","password"); sleep 10; $content= s/202.36.7.8/202.36.7.8/; $response->$content; exit; ------------------------------------------------------------
following is the error i am getting
----------------------------------- Not a CODE reference at (eval 8) line 1. ------------------------------------------------------------
how can i solve this problem or else where can i look for the appropriate cmds to achieve this ?

Replies are listed 'Best First'.
Re: unable to configure a device from HTTP page using perl script
by jasonk (Parson) on Nov 18, 2007 at 19:09 UTC

    What you are trying to do with this code doesn't make any sense, for a number of reasons.

    • you are attempting to set authorization information on a request that you have already sent to the server.
    • You are sleeping for no apparent reason
    • $content = s/202.36.7.8/202.36.7.8/; doesn't even come close to doing what you are attempting to do (in fact it doesn't do much of anything).
    • $response->$content also doesn't do anything.

    From your description of what you are trying to do, and your code, I'm guessing you are attempting to configure a router or a wireless access point or something like that with a web interface. In that case you need to step back and think about exactly what it is you are trying to achieve. I would guess it goes something like this:

    • Request http://192.168.1.1/ with basic authentication
    • Navigate to the form that contains the ip address
    • Change the value of the IP address in the form
    • Submit the form

    If that is the case, you probably want to start with WWW::Mechanize, which is designed for exactly this sort of applications. In order to use it you would do something like this:

    use strict; # <- always start with this use warnings; # <- this is good too use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->credentials( 'admin', 'password' ); $mech->get( 'http://192.168.1.1/' ); $mech->follow_link( test_regex => qr/configuration/ ); $mech->submit_form( form_number => 1, fields => { ip_address => '202.36.7.8', }, );

    Of course you will have to adjust this to suit the actual interface you are attempting to interact with.


    We're not surrounded, we're in a target-rich environment!
Re: unable to configure a device from HTTP page using perl script
by igelkott (Priest) on Nov 18, 2007 at 18:57 UTC
    Really simple question: Did you define $httpRequestMethod? Try using GET.