ActivePerl error message? Router script. Please help.Newbie

Discussion in 'Perl Misc' started by wrreisen2@yahoo.com, May 17, 2006.

  1. Guest

    Hi,

    I have installed ActivePerl on Windows XP SP2 professional and have
    tried running a script to restart my router: it always gives out this
    message:

    Can't locate Net/Telnet.pm in @INC (@INC contains: C:/Perl/lib
    C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\router.pl line 5.
    BEGIN failed--compilation aborted at c:\inetpub\wwwroot\perl\router.pl
    line 5.

    By default ActivePerl has installed Perl has been installed C:/Perl

    I am running IIS.

    The examples given in activeperl say that
    "Note: the examples assume that PerlEx is installed on this machine,
    and that the address http://localhost/PerlEx/scriptname is valid."

    So I created a directory in c:\inetpub\wwwroot\ called perl and copied
    and pasted all the files from C:/Perl into this directory in an attempt
    to get this localhost to work. I have been running my script in
    c:\inetpub\wwwroot\perl\
    I've typed into Internet Explorer: http://localhost/perl/router.pl and
    get the above error.

    The script I have been trying to get to work is below:

    I also tried turning on the starting the telnet service XP but this
    didn't make any difference.
    ***************************************************************

    Here's some Perl that I've been playing with at home and at work
    (being diverted from seeing some friends on Saturday morning to detour
    into work to reboot the router provides an incentive to make sure the
    ADSL line stays up). I run it from a cron job every 5 minutes.

    Work: Vigor2600
    Home: SpeedTouch 510

    Both of them sometimes need a kick.

    Notes: you will need to:
    run the script as root if you use ICMP echo requests
    change the IP addresses that it pings
    change the username and password
    change the command to reboot the system
    do a bit of tidying up, especially if you are using Windows

    Apologies to any Perl hackers out there for the coding style, from an
    old fart who still thinks in Algol-60, -68, Fortran and C.

    ------8<------8<------8<------8<------8<------8<------8<------8<------8<
    #! /usr/bin/perl -w

    use strict;

    use Net::Telnet;
    use Net::ping;
    use Sys::Syslog;
    use Mail::Mailer;

    # RFC1918 IP address of your router
    my $localip = "192.168.0.254";

    # a list of IP addresses to ping that are 1) few hops away, and 2)
    # likely to be stable

    # cheapest first
    # next IP upstream 0.0.0.0 (from a traceroute)
    # Your ISP's DNS servers: 0.0.0.1 & 0.0.0.2
    # Your ISP's web server: 0.0.0.3
    # i.root-servers.net: 192.36.148.17
    # and any others you can think of

    my @netips = ("0.0.0.0", "0.0.0.1", "0.0.0.2", "0.0.0.3",
    "192.36.148.17" );
    my $ip;
    my $ok = 0;
    my $mailer;

    my $t; # telnet socket
    my $p; # ping

    my @lines;
    my $i;
    my $tmp;

    $p = Net::ping->new("icmp");

    # log to syslog
    openlog( "routerping", "", "user" );

    foreach $ip (@netips)
    {
    if ( $p->ping($ip) )
    {
    $ok = 1;
    last;
    }
    else
    {
    syslog( 'debug', "can't ping %s", $ip );
    }
    }

    if ( ! $ok )
    {
    syslog( 'debug', "%s", "rebooting router" );

    # make sure that there is a route to the ADSL router's local
    # IP address
    system( "ip route add " . $localip . "/32 dev eth1" );

    $t = Net::Telnet->new( Timeout => 10, Prompt => '/> /', Host =>
    $localip );

    $t->input_log( "/var/log/router.log" );

    # if your router asks for a username and password, use this:
    $t->login("Administrator", "zxc314" ) or die "login failed";

    # else if it just prompts for a password use this:

    $t->waitfor("/Password:/" ) or die "login waitfor 1 failed";
    $t->print("fr0gR0utr" ) or die "login print failed";
    $t->waitfor("/> /" ) or die "login waitfor 2 failed";

    @lines = $t->cmd("adsl status");
    # or perhaps
    @lines = $t->cmd("adsl info");

    $t->print("system reboot");
    # or perhaps
    $t->print("sys reboot");

    $t->close;

    $mailer = Mail::Mailer->new("smtp", Server => "localhost") || die
    "can't new mail";

    $mailer->open({ From => 'root',
    To => 'root',
    Subject=> "router reboot",
    }) or die "can't open mail";

    print $mailer "router reboot";

    $mailer->close() || die "can't close mail";
    }
    ------8<------8<------8<------8<------8<------8<------8<------8<------8<
     
    , May 17, 2006
    #1
    1. Advertising

  2. Guest Guest

    In comp.lang.perl.misc wrote:
    : Hi,

    : tried running a script to restart my router: it always gives out this
    : message:

    : Can't locate Net/Telnet.pm in @INC (@INC contains: C:/Perl/lib
    : C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\router.pl line 5.
    : BEGIN failed--compilation aborted at c:\inetpub\wwwroot\perl\router.pl
    : line 5.

    This message says it all: Can't locate Net/Telnet.pm at line 5.

    [...lots of stuff snipped here...]

    : use Net::Telnet; # And this is line 5 of your code.

    [...code snipped...]

    By default, ActiveState's Perl installation doesn't contain the Net::
    Telnet module, only Net::HTTP is there. You just have to install Net::
    Telnet from CPAN, ideally via ActivePerl's install manager.

    The other measures you described in your mail are not necessary; if
    ActiveState Perl is allowed to install properly, then it will any .pl
    script anywhere will start up.

    Oliver.


    --
    Dr. Oliver Corff e-mail: -berlin.de
     
    Guest, May 17, 2006
    #2
    1. Advertising

  3. Guest

    Hi,

    Thanks Oliver for your help.

    I have added all the .pm files from CPAN in the appropriate directories

    Telnet.pm
    Mailer.pm
    Syslog.pm
    template.pm

    Please could you explain this error message:

    Undefined subroutine &main::eek:penlog called at
    c:\inetpub\wwwroot\perl\router.pl line 38.

    Thankyou.

    Line 38 says:

    openlog( "routerping", "", "user" );
     
    , May 17, 2006
    #3
  4. wrote in news:1147879258.999380.225030
    @j73g2000cwa.googlegroups.com:

    > I have added all the .pm files from CPAN in the appropriate directories
    >
    > Telnet.pm
    > Mailer.pm
    > Syslog.pm
    > template.pm


    With your lack of experience and expertise, how do you know you installed
    them in the correct directories?

    Please use ppm which is distributed with AS Perl to find and install
    packages.

    > Please could you explain this error message:


    Please, could you read the posting guidelines and follow them to help us
    help you?

    While you are at it, please also quote properly when replying.

    > Undefined subroutine &main::eek:penlog called at
    > c:\inetpub\wwwroot\perl\router.pl line 38.
    >
    > Thankyou.
    >
    > Line 38 says:
    >
    > openlog( "routerping", "", "user" );


    What does line 42 say?

    Sinan
     
    A. Sinan Unur, May 17, 2006
    #4
  5. Guest Guest

    In comp.lang.perl.misc wrote:
    : Hi,

    : I have added all the .pm files from CPAN in the appropriate directories

    : Telnet.pm
    : Mailer.pm
    : Syslog.pm
    : template.pm

    Did you install manually or let the package makefile do the work?

    : Please could you explain this error message:

    : Undefined subroutine &main::eek:penlog called at
    : c:\inetpub\wwwroot\perl\router.pl line 38.

    : openlog( "routerping", "", "user" );

    No, I can't. The following complete minimal example does not produce
    any error message on my system:

    #!/usr/bin/perl
    use warnings;
    use strict;
    use Sys::Syslog;
    openlog("","","user");
    __END__

    Can you try this and verify?

    Oliver.

    --
    Dr. Oliver Corff e-mail: -berlin.de
     
    Guest, May 17, 2006
    #5
  6. wrote:
    > Hi,
    >
    > Thanks Oliver for your help.
    >
    > I have added all the .pm files from CPAN in the appropriate directories
    >
    > Telnet.pm
    > Mailer.pm
    > Syslog.pm
    > template.pm
    >
    > Please could you explain this error message:
    >
    > Undefined subroutine &main::eek:penlog called at
    > c:\inetpub\wwwroot\perl\router.pl line 38.
    >
    > Thankyou.
    >
    > Line 38 says:
    >
    > openlog( "routerping", "", "user" );
    >


    Just a guess but `openlog` may be a Sys::Syslog method... (I thought
    Sys::Syslog was Unix only too but maybe there's been some kind of Win32
    port).

    --
    Charles DeRykus
     
    Charles DeRykus, May 17, 2006
    #6
  7. John Bokma Guest

    wrote:

    > Hi,
    >
    > Thanks Oliver for your help.
    >
    > I have added all the .pm files from CPAN in the appropriate directories
    >
    > Telnet.pm
    > Mailer.pm
    > Syslog.pm
    > template.pm


    why didn't you do:

    C:> ppm install Net-Telnet

    ?

    Note that if you have set up your Win XP Pro properly, you have to run the
    command prompt as Administrator (or a user with admin rights) in order to
    be able to execute ppm. If it works out of the box, you probably should
    rethink your account rights.

    --
    John Bokma Freelance software developer
    &
    Experienced Perl programmer: http://castleamber.com/
     
    John Bokma, May 17, 2006
    #7
  8. Guest

    Hi,

    Thanks for all your help. I installed
    > Telnet.pm
    > Mailer.pm
    > Syslog.pm
    > template.pm manually because I couldn't work out how to get ppm to do anything. Now I've got it ppm working.

    So now I've:
    1:) uninstalled ActivePerl
    2:) Restarted WinXP Pro
    3:) deleted c:\Perl to remove any of my previous manually installed .pm
    files.
    4:) Reinstalled ActivePerl
    5:) Tried running the Perl script mentioned in the first post in this
    thread.
    6:) Of course got the same error message as 1st mentioned:
    C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\router.pl line 5.
    BEGIN failed--compilation aborted at c:\inetpub\wwwroot\perl\router.pl
    line 5.
    7:) Did C:> ppm install Net-Telnet
    8:) Ran Perl Script as mentioned in the first post.
    9:) Get error:
    Can't locate Sys/Syslog.pm in @INC (@INC contains: C:/Perl/lib
    C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\router.pl line 7.
    BEGIN failed--compilation aborted at c:\inetpub\wwwroot\perl\router.pl
    line 7.
    10:) Did c:>ppm search sys-syslog
    Searching in Active Repositories
    No matches for 'sys-syslog'; see 'help search'.

    Does this mean as Charles DeRykus says that there is no Win32 port of
    Sys-syslog?

    Is there anyway of getting this script to work in windows?

    When I run:
    #!/usr/bin/perl
    use warnings;
    use strict;
    use Sys::Syslog;
    openlog("","","user");
    __END__
    I get the same error message:

    Can't locate Sys/Syslog.pm in @INC (@INC contains: C:/Perl/lib
    C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\olivertest2.pl line 4.
    BEGIN failed--compilation aborted at
    c:\inetpub\wwwroot\perl\olivertest2.pl line 4.

    >What does line 42 say?

    if ( $p->ping($ip) )

    Thanks. Are there any similar scripts out there that may do the same
    thing that would work in Windows. Thanks.
     
    , May 18, 2006
    #8
  9. Nick Guest

    wrote:
    > Hi,
    >
    > Thanks for all your help. I installed
    >
    >>Telnet.pm
    >>Mailer.pm
    >>Syslog.pm
    >>template.pm manually because I couldn't work out how to get ppm to do anything. Now I've got it ppm working.

    >
    > So now I've:
    > 1:) uninstalled ActivePerl
    > 2:) Restarted WinXP Pro
    > 3:) deleted c:\Perl to remove any of my previous manually installed .pm
    > files.
    > 4:) Reinstalled ActivePerl
    > 5:) Tried running the Perl script mentioned in the first post in this
    > thread.
    > 6:) Of course got the same error message as 1st mentioned:
    > C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\router.pl line 5.
    > BEGIN failed--compilation aborted at c:\inetpub\wwwroot\perl\router.pl
    > line 5.
    > 7:) Did C:> ppm install Net-Telnet
    > 8:) Ran Perl Script as mentioned in the first post.
    > 9:) Get error:
    > Can't locate Sys/Syslog.pm in @INC (@INC contains: C:/Perl/lib
    > C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\router.pl line 7.
    > BEGIN failed--compilation aborted at c:\inetpub\wwwroot\perl\router.pl
    > line 7.
    > 10:) Did c:>ppm search sys-syslog
    > Searching in Active Repositories
    > No matches for 'sys-syslog'; see 'help search'.
    >
    > Does this mean as Charles DeRykus says that there is no Win32 port of
    > Sys-syslog?
    >
    > Is there anyway of getting this script to work in windows?
    >
    > When I run:
    > #!/usr/bin/perl
    > use warnings;
    > use strict;
    > use Sys::Syslog;
    > openlog("","","user");
    > __END__
    > I get the same error message:
    >
    > Can't locate Sys/Syslog.pm in @INC (@INC contains: C:/Perl/lib
    > C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\olivertest2.pl line 4.
    > BEGIN failed--compilation aborted at
    > c:\inetpub\wwwroot\perl\olivertest2.pl line 4.
    >
    >
    >>What does line 42 say?

    >
    > if ( $p->ping($ip) )
    >
    > Thanks. Are there any similar scripts out there that may do the same
    > thing that would work in Windows. Thanks.
    >


    If you don't really need the logging capabilities, you could always just
    comment out line 32...?

    xF,

    ....Nick
     
    Nick, May 18, 2006
    #9
  10. Nick Guest

    [...]line 32...[...]

    By which, of course, I meant "38"!
     
    Nick, May 18, 2006
    #10
  11. Guest

    Thanks Nick

    Have commented out line 7
    # use Sys::Syslog;
    and line 38

    When I run the script it now gives:
    Can't locate Mail/Mailer.pm in @INC (@INC contains: C:/Perl/lib
    C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\router.pl line 8.
    BEGIN failed--compilation aborted at c:\inetpub\wwwroot\perl\router.pl
    line 8.
    I did c:>ppm search mail-mailer
    There isn't one. I presume that this means that mail-mailer isn't
    available for Win32?
    I would guess it wouldn't work if I commented out the lines to do with
    this Mail-mailer module?

    $mailer = Mail::Mailer->new("smtp", Server => "localhost") || die
    "can't new mail";

    $mailer->open({ From => 'root',
    To => 'root',
    Subject=> "router reboot",
    }) or die "can't open mail";

    print $mailer "router reboot";

    $mailer->close() || die "can't close mail";
    }

    Is there some other way? Thanks again.
     
    , May 18, 2006
    #11
  12. Guest

    The solution might be to run an Linux emulator on XP and run it on that
    I suppose?
     
    , May 18, 2006
    #12
  13. wrote:
    > Thanks Nick
    >
    > Have commented out line 7
    > # use Sys::Syslog;
    > and line 38
    >
    > When I run the script it now gives:
    > Can't locate Mail/Mailer.pm in @INC (@INC contains: C:/Perl/lib
    > C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\router.pl line 8.
    > BEGIN failed--compilation aborted at c:\inetpub\wwwroot\perl\router.pl
    > line 8.
    > I did c:>ppm search mail-mailer
    > There isn't one. I presume that this means that mail-mailer isn't
    > available for Win32?
    > I would guess it wouldn't work if I commented out the lines to do with
    > this Mail-mailer module?
    >
    > $mailer = Mail::Mailer->new("smtp", Server => "localhost") || die
    > "can't new mail";
    >
    > $mailer->open({ From => 'root',
    > To => 'root',
    > Subject=> "router reboot",
    > }) or die "can't open mail";
    >
    > print $mailer "router reboot";
    >
    > $mailer->close() || die "can't close mail";
    > }
    >
    > Is there some other way? Thanks again.
    >


    Just comment out all the mailer stuff as well. It's for notification, so
    - unless you need it for some particular reason - you can get rid of it.

    If you do want logging capabilities, then it's a simple enough matter to
    just write directly to a file, somewhere. A quick read-up on Perl will
    tell you how :)

    xF,

    ....Nick
     
    Nicholas Thomas, May 18, 2006
    #13
  14. l v Guest

    wrote:
    > Hi,
    >
    > Thanks for all your help. I installed
    >
    >>Telnet.pm
    >>Mailer.pm
    >>Syslog.pm
    >>template.pm manually because I couldn't work out how to get ppm to do anything. Now I've got it ppm working.

    >
    > So now I've:
    > 1:) uninstalled ActivePerl
    > 2:) Restarted WinXP Pro
    > 3:) deleted c:\Perl to remove any of my previous manually installed .pm
    > files.
    > 4:) Reinstalled ActivePerl
    > 5:) Tried running the Perl script mentioned in the first post in this
    > thread.
    > 6:) Of course got the same error message as 1st mentioned:
    > C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\router.pl line 5.
    > BEGIN failed--compilation aborted at c:\inetpub\wwwroot\perl\router.pl
    > line 5.
    > 7:) Did C:> ppm install Net-Telnet
    > 8:) Ran Perl Script as mentioned in the first post.
    > 9:) Get error:
    > Can't locate Sys/Syslog.pm in @INC (@INC contains: C:/Perl/lib
    > C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\router.pl line 7.
    > BEGIN failed--compilation aborted at c:\inetpub\wwwroot\perl\router.pl
    > line 7.
    > 10:) Did c:>ppm search sys-syslog
    > Searching in Active Repositories
    > No matches for 'sys-syslog'; see 'help search'.
    >
    > Does this mean as Charles DeRykus says that there is no Win32 port of
    > Sys-syslog?
    >
    > Is there anyway of getting this script to work in windows?
    >
    > When I run:
    > #!/usr/bin/perl
    > use warnings;
    > use strict;
    > use Sys::Syslog;
    > openlog("","","user");
    > __END__
    > I get the same error message:
    >
    > Can't locate Sys/Syslog.pm in @INC (@INC contains: C:/Perl/lib
    > C:/Perl/site/lib .) at c:\inetpub\wwwroot\perl\olivertest2.pl line 4.
    > BEGIN failed--compilation aborted at
    > c:\inetpub\wwwroot\perl\olivertest2.pl line 4.
    >
    >
    >>What does line 42 say?

    >
    > if ( $p->ping($ip) )
    >
    > Thanks. Are there any similar scripts out there that may do the same
    > thing that would work in Windows. Thanks.
    >


    If you are only going to run on windows, you can log in the windows
    event log by using Win32::EventLog.

    --

    Len
     
    l v, May 18, 2006
    #14
  15. Guest

    Thanks Nick & Len,

    I have commented out all to do with the Mailer and Syslog now. I get
    the error message:

    CGI Error
    The specified CGI application misbehaved by not returning a complete
    set of HTTP headers. The headers it did return are:

    'ip' is not recognized as an internal or external command,
    operable program or batch file.
    problem connecting to "192.168.0.254", port 23: Unknown error at
    c:\inetpub\wwwroot\perl\router_be.pl line 61

    192.168.0.254 is the IP of my router on my network. Why have a go on
    port 23?

    http://www.edimax.nl/download/manual/AR-7024_M.zip is the manual for
    this router. Is there something I should configure to do with ports on
    this?

    There is this from the manual? Would these be relevant:

    HTTP Server Port: This field allows the user to specify the port of the
    Web access. . For example, when it is changed to 1001, the HTTP server
    address for the LAN side is http://10.0.0.2:1001

    And:

    3.3.9 Configuration - Virtual Server Configuration

    The Virtual Server Configuration page allows the user to set the
    configuration of Virtual Server. The Conexant firmware includes the
    Free BSD version firewall. All UDP/TCP ports are protected from
    intrusion. If any specific local PCs need to be mapped to the UDP/TCP
    port on WAN side, please input the mappings here.



    Public Port: This field allows the user to enter the port number of the
    Public Network.

    Private Port: This field allows the user to enter the port number of
    the Private Network.In most cases, the private port number is same as
    public port number.

    Host IP Address: This field allows the user to enter the private
    network IP address for the particular sever.

    Thanks again.
     
    , May 18, 2006
    #15
  16. Guest

    Sorry forgot. This is the code now. Thanks.

    #! /usr/bin/perl -w

    use strict;

    use Net::Telnet;
    use Net::ping;
    #use Sys::Syslog;
    #use Mail::Mailer;

    # RFC1918 IP address of your router
    my $localip = "192.168.0.254";

    # a list of IP addresses to ping that are 1) few hops away, and 2)
    # likely to be stable

    # cheapest first
    # next IP upstream 0.0.0.0 (from a traceroute)
    # Your ISP's DNS servers: 0.0.0.1 & 0.0.0.2
    # Your ISP's web server: 0.0.0.3
    # i.root-servers.net: 192.36.148.17
    # and any others you can think of

    my @netips = ("0.0.0.0", "0.0.0.1", "0.0.0.2", "0.0.0.3",
    "192.36.148.17" );
    my $ip;
    my $ok = 0;
    my $mailer;

    my $t; # telnet socket
    my $p; # ping

    my @lines;
    my $i;
    my $tmp;

    $p = Net::ping->new("icmp");

    # log to syslog
    #openlog( "routerping", "", "user" );

    foreach $ip (@netips)
    {
    if ( $p->ping($ip) )
    {
    $ok = 1;
    last;
    }
    else
    {
    # syslog( 'debug', "can't ping %s", $ip );
    }
    }

    if ( ! $ok )
    {
    # syslog( 'debug', "%s", "rebooting router" );

    # make sure that there is a route to the ADSL router's local
    # IP address
    system( "ip route add " . $localip . "/32 dev eth1" );

    $t = Net::Telnet->new( Timeout => 10, Prompt => '/> /', Host =>
    $localip );

    $t->input_log( "/var/log/router.log" );

    # if your router asks for a username and password, use this:
    $t->login("Administrator", "zxc314" ) or die "login failed";

    # else if it just prompts for a password use this:

    $t->waitfor("/Password:/" ) or die "login waitfor 1 failed";
    $t->print("fr0gR0utr" ) or die "login print failed";
    $t->waitfor("/> /" ) or die "login waitfor 2 failed";

    @lines = $t->cmd("adsl status");
    # or perhaps
    @lines = $t->cmd("adsl info");

    $t->print("system reboot");
    # or perhaps
    $t->print("sys reboot");

    $t->close;

    # $mailer = Mail::Mailer->new("smtp", Server => "localhost") || die
    "can't new mail";
    #
    # $mailer->open({ From => 'root',
    # To => 'root',
    # Subject=> "router reboot",
    # }) or die "can't open mail";
    #
    # print $mailer "router reboot";

    # $mailer->close() || die "can't close mail";
    }
     
    , May 18, 2006
    #16
  17. l v Guest

    wrote:
    > Thanks Nick & Len,
    >
    > I have commented out all to do with the Mailer and Syslog now. I get
    > the error message:
    >
    > CGI Error
    > The specified CGI application misbehaved by not returning a complete
    > set of HTTP headers. The headers it did return are:


    You need to return valid HTTP headers back to your browser in order to
    tell it what to do.
    print "Content-type: text/html\n\n";

    >
    > 'ip' is not recognized as an internal or external command,
    > operable program or batch file.
    > problem connecting to "192.168.0.254", port 23: Unknown error at
    > c:\inetpub\wwwroot\perl\router_be.pl line 61

    from your code in the other post you tell your pc/server to run the
    command ip route add ... . I'm guessing that the command is invalid and
    should be route add ... or are you trying to run that command remotely
    on your ADSL router?
    > system( "ip route add " . $localip . "/32 dev eth1" );


    >
    > 192.168.0.254 is the IP of my router on my network. Why have a go on
    > port 23?

    Telnet uses port 23.
    >
    > http://www.edimax.nl/download/manual/AR-7024_M.zip is the manual for
    > this router. Is there something I should configure to do with ports on
    > this?
    >

    [snip]
    > Thanks again.
    >



    --

    Len
     
    l v, May 18, 2006
    #17
  18. Firstly, as the original author of this code, my apologies to the perl
    groups for the inconvenience.

    The original posting was accompanied by the text:

    | Notes: you will need to:
    | run the script as root if you use ICMP echo requests
    | change the IP addresses that it pings
    | change the username and password
    | change the command to reboot the system
    | do a bit of tidying up, especially if you are using Windows

    | Apologies to any Perl hackers out there for the coding style, from an
    | old fart who still thinks in Algol-60, -68, Fortran and C.

    On 18 May 2006 08:52:12 -0700, said:

    > I have commented out all to do with the Mailer and Syslog now. I get
    > the error message:


    > CGI Error The specified CGI application misbehaved by not returning
    > a complete set of HTTP headers. The headers it did return are:


    How on earth are you getting those errors? This script has nothing to
    do with the web, browsers or HTTP. Run the script from a command line.

    > 'ip' is not recognized as an internal or external command, operable
    > program or batch file. problem connecting to "192.168.0.254", port
    > 23: Unknown error at c:\inetpub\wwwroot\perl\router_be.pl line 61


    > 192.168.0.254 is the IP of my router on my network. Why have a go on
    > port 23?


    > Sorry forgot. This is the code now. Thanks.


    <snippage>

    > use Net::Telnet;


    Telnet is a ancient protocol used as a command line interface
    to remote computers. It runs on port 23.

    Windows has (or did last time I looked) a telnet application. You can
    probably invoke it with something like Windows Menu->Run Command and
    enter telnet in the box. Supply the IP address of your router, and see
    if you get a response. Then see what commands it accepts. "help" or "?"
    (without the quotes) are often useful.

    > my $localip = "192.168.0.254";


    That's the same as my IP router's IP address. Coincidence? Or do you need to
    change it?

    > # a list of IP addresses to ping that are 1) few hops away, and 2)
    > # likely to be stable


    > my @netips = ("0.0.0.0", "0.0.0.1", "0.0.0.2", "0.0.0.3",
    > "192.36.148.17" );


    Most of those IP addresses are clearly invalid, and as I originally said,
    you will need to change them.

    > # if your router asks for a username and password, use this:
    > $t->login("Administrator", "xxx" ) or die "login failed";


    > # else if it just prompts for a password use this:


    > $t->waitfor("/Password:/" ) or die "login waitfor 1 failed";
    > $t->print("xxx" ) or die "login print failed";
    > $t->waitfor("/> /" ) or die "login waitfor 2 failed";


    Read the comments! There are two options here, you only need one. You
    also need to change the password to match that set on your router.

    > @lines = $t->cmd("adsl status");
    > # or perhaps
    > @lines = $t->cmd("adsl info");


    Again, you only need one of these lines.

    > $t->print("system reboot");
    > # or perhaps
    > $t->print("sys reboot");


    And again!

    --
    Alan J. Wylie http://www.wylie.me.uk/
    "Perfection [in design] is achieved not when there is nothing left to add,
    but rather when there is nothing left to take away."
    -- Antoine de Saint-Exupery
     
    Alan J. Wylie, May 18, 2006
    #18
  19. On Thu, 18 May 2006, l v wrote:

    > wrote:
    > > CGI Error
    > > The specified CGI application misbehaved by not returning a complete
    > > set of HTTP headers. The headers it did return are:


    I haven't been following this thread, but it's evident at this point
    that something is being invoked as a CGI script. My answer is
    predicated on that...

    > You need to return valid HTTP headers back to your browser in order
    > to tell it what to do.


    More to the point: from a CGI script, you need to return valid CGI
    response headers to the web server (see perlfaq9 for a brief
    discussion). it's kind-of unfortunate that the error report muddles
    up this issue in just the way that many CGI users tend to muddle it
    up. The similarity between CGI response header and HTTP response
    headers is intentional, but there are subtle differences, and it's
    best IMHO to keep a careful grasp on which is which.

    It's the server's responsibility to construct a complete and valid set
    of HTTP response headers to send to the client/browser - based on the
    valid *CGI response* which the server gets from the script.

    > print "Content-type: text/html\n\n";


    That is, in its way, a perfectly fine *CGI* response header, together
    with the extra \n which terminates the CGI response headers.

    As a valid HTTP header, on the other hand, it would not pass muster,
    since the HTTP specification calls for precisely CRLF as line
    terminator ( expressed e.g as \015\012 in Perl notation). And anyway
    a proper HTTP response calls for more than just a Content-type header.

    Furthermore, it's not clear to me that the output was supposed to be
    HTML. If it was, in fact, plain text, then the appropriate
    content-type would be be text/plain. On the other hand, if it's meant
    to be HTML then any data acquired from an external source ought to be
    HTML-encoded, or at least carefully filtered, to avoid security
    compromises of the kind which is usually, though somewhat
    inaccurately, known as "cross site scripting" (XSS).

    In any case, any text/* content-type ought to also have its proper
    character encoding specified (with appropriate charset= attribute).

    best

    p.s none of the cross-posted groups seems entirely on-topic for this
    CGI discussion, but, out of the ones used, I'm suggesting f'ups to
    c.l.p.misc as the best match.
     
    Alan J. Flavell, May 18, 2006
    #19
  20. John Bokma Guest

    l v <> wrote:

    [CGI]

    > print "Content-type: text/html\n\n";


    Don't do that (or advice that), use the header function that comes with
    CGI.pm. It might stop you from common mistakes (like typing one \n)

    --
    John Bokma Freelance software developer
    &
    Experienced Perl programmer: http://castleamber.com/
     
    John Bokma, May 18, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. marko
    Replies:
    0
    Views:
    1,101
    marko
    Jul 19, 2003
  2. KK
    Replies:
    2
    Views:
    595
    Big Brian
    Oct 14, 2003
  3. kiran & Dev

    wse router --encrypting the message thru policies

    kiran & Dev, Mar 9, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    114
    kiran & Dev
    Mar 9, 2005
  4. Ted
    Replies:
    7
    Views:
    562
    Sisyphus
    Dec 16, 2006
  5. script to reset router?

    , Jan 13, 2006, in forum: Javascript
    Replies:
    2
    Views:
    90
Loading...

Share This Page