W
wrreisen2
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:ing;
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:ing->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<
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:ing;
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:ing->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<