W
wrreisen2
Hi, Thanks again for all your help.
My router has ip 10.0.0.2
I press start, run then type telnet.
At the telnet prompt I type "open 10.0.0.2"
Connecting To 10.0.0.2...Could not open connection to the host, on port
23: Connect failed
I tried pinging 10.0.0.2 from the command prompt and it comes back
fine:
Reply from 10.0.0.2: bytes=32 time<1ms TTL=64
Reply from 10.0.0.2: bytes=32 time<1ms TTL=64
Reply from 10.0.0.2: bytes=32 time<1ms TTL=64
Reply from 10.0.0.2: bytes=32 time<1ms TTL=64
Ping statistics for 10.0.0.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
I have now commented out where there are alternatives as kindly
described by Alan J Wylie.
When I connect to my router through internet explorer I have to type in
both username and password.
So I've left in line 66:
$t->login("admin", "epicrouter" ) or die "login failed";
and commented out lines 70-72
# $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";
I've left in line 74:
@lines = $t->cmd("adsl status");
because in the manual
http://www.edimax.nl/download/manual/AR-7024_M.zip it has a section on
a
configuration html page called ADSL STATUS (doesn't mention telnet
commands anywhere though. It
doesn't mention "adsl info" anywhere in the manual so I have commented
out line 76:
# @lines = $t->cmd("adsl info");
AFAIK I don't see a way of finding out which commands the router may
respond to and which it doesn't
except by trial and error. The router manual doesn' mention the terms
"system reboot" or "sys
reboot". So I've just left in line 78:
$t->print("system reboot");
and commented out line 80:
$t->print("sys reboot");
I've called this perl script router.pl. so at the dos command prompt in
XP I type
c:\perl router.pl
and press enter. It takes about 10seconds then the command prompt comes
back up again.
c:\
I presume as I've commented out all the logging and mailing functions
in this script there's no way
of knowing what its doing without altering it and perhaps adding in the
Win32-eventlog. When the
command prompt pops back again I presume it stops working?
With ppm I searched for Win32-eventlog it found "Win32-eventlog-carp"
so I installed this with ppm:
Extracting 5/5: blib/arch/auto/Win32/EventLog/Carp/.exists
Installing C:\Perl\html\site\lib\Win32\EventLog\Carp.html
Installing C:\Perl\site\lib\Win32\EventLog\Carp.pm
Successfully installed win32-eventlog-carp version 1.21 in ActivePerl
5.8.8.817.
To use this event log should I put:
"Use Win32::eventlog::carp" at the beginning
Would line 40 be okay to uncomment to work with this
win32-eventlog-carp?
# openlog( "routerping", "", "user" );
Would line 51 change from:
# syslog( 'debug', "can't ping %s", $ip );
to:
eventlog( 'debug', "can't ping %s", $ip );
Would line 57 change from:
# syslog( 'debug', "%s", "rebooting router" );
to:
eventlog( 'debug', "%s", "rebooting router" );
Would line 65 stay the same?
$t->input_log( "/var/log/router.log" );
As mentioned by Len I tried adding the print "Content-type:
text/html\n\n"; at line 23 so its shifted
the lines of code down 2 lines.
When run in InternetExplorer you don't get this part of the error
message anymore:
CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers. The headers
it did return are:
Error message.
As kindly recommended by Len I've tried changing line 59 from
system( "ip route add " . $localip . "/32 dev eth1" );
to
system( "route add " . $localip . "/32 dev eth1" );
instead of the previous error:
'ip' is not recognized as an internal or external command, operable
program or batch file. problem
connecting to "10.0.0.2", port 23: Unknown error at
c:\inetpub\wwwroot\perl\router_01.pl line 63
I get this error:
route: bad destination address 10.0.0.2/32
problem connecting to "10.0.0.2", port 23: Unknown error at
c:\inetpub\wwwroot\perl\router_01.pl line
63
Line 63 is:
$t = Net::Telnet->new( Timeout => 10, Prompt => '/> /', Host =>
$localip );
I'm happy running this script at the command prompt if that can work
reliably I was just trying it
internet explorer just because the active perl manual suggested running
its examples from
http://localhost/perl/ so under windows xp it seemed the logical choice
to try it in Internet
Explorer. The end result I would like is something that will run
continually all the time under
windows XP whenever the computer is switched on. Could you run this as
a service in someway or is
there a better way?
Thanks for all your help.
The Script now reads:
#! /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 = "10.0.0.2";
# 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) [I'm on a dynamic ip so
1st upstream ip changes from day to
# day so have put in 4.68.116.98 from further up the traceroute
# Your ISP's DNS servers: 212.159.13.49 & 212.159.13.50
# Your ISP's web server: 84.92.4.90
# i.root-servers.net: 192.36.148.17
# and any others you can think of
print "Content-type: text/html\n\n";
my @netips = ("194.166.128.72", "212.159.13.49", "212.159.13.50",
"84.92.4.90", "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( "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("admin", "epicrouter" ) 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";
}
My router has ip 10.0.0.2
I press start, run then type telnet.
At the telnet prompt I type "open 10.0.0.2"
Connecting To 10.0.0.2...Could not open connection to the host, on port
23: Connect failed
I tried pinging 10.0.0.2 from the command prompt and it comes back
fine:
Reply from 10.0.0.2: bytes=32 time<1ms TTL=64
Reply from 10.0.0.2: bytes=32 time<1ms TTL=64
Reply from 10.0.0.2: bytes=32 time<1ms TTL=64
Reply from 10.0.0.2: bytes=32 time<1ms TTL=64
Ping statistics for 10.0.0.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
I have now commented out where there are alternatives as kindly
described by Alan J Wylie.
When I connect to my router through internet explorer I have to type in
both username and password.
So I've left in line 66:
$t->login("admin", "epicrouter" ) or die "login failed";
and commented out lines 70-72
# $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";
I've left in line 74:
@lines = $t->cmd("adsl status");
because in the manual
http://www.edimax.nl/download/manual/AR-7024_M.zip it has a section on
a
configuration html page called ADSL STATUS (doesn't mention telnet
commands anywhere though. It
doesn't mention "adsl info" anywhere in the manual so I have commented
out line 76:
# @lines = $t->cmd("adsl info");
AFAIK I don't see a way of finding out which commands the router may
respond to and which it doesn't
except by trial and error. The router manual doesn' mention the terms
"system reboot" or "sys
reboot". So I've just left in line 78:
$t->print("system reboot");
and commented out line 80:
$t->print("sys reboot");
I've called this perl script router.pl. so at the dos command prompt in
XP I type
c:\perl router.pl
and press enter. It takes about 10seconds then the command prompt comes
back up again.
c:\
I presume as I've commented out all the logging and mailing functions
in this script there's no way
of knowing what its doing without altering it and perhaps adding in the
Win32-eventlog. When the
command prompt pops back again I presume it stops working?
With ppm I searched for Win32-eventlog it found "Win32-eventlog-carp"
so I installed this with ppm:
Extracting 5/5: blib/arch/auto/Win32/EventLog/Carp/.exists
Installing C:\Perl\html\site\lib\Win32\EventLog\Carp.html
Installing C:\Perl\site\lib\Win32\EventLog\Carp.pm
Successfully installed win32-eventlog-carp version 1.21 in ActivePerl
5.8.8.817.
To use this event log should I put:
"Use Win32::eventlog::carp" at the beginning
Would line 40 be okay to uncomment to work with this
win32-eventlog-carp?
# openlog( "routerping", "", "user" );
Would line 51 change from:
# syslog( 'debug', "can't ping %s", $ip );
to:
eventlog( 'debug', "can't ping %s", $ip );
Would line 57 change from:
# syslog( 'debug', "%s", "rebooting router" );
to:
eventlog( 'debug', "%s", "rebooting router" );
Would line 65 stay the same?
$t->input_log( "/var/log/router.log" );
As mentioned by Len I tried adding the print "Content-type:
text/html\n\n"; at line 23 so its shifted
the lines of code down 2 lines.
When run in InternetExplorer you don't get this part of the error
message anymore:
CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers. The headers
it did return are:
Error message.
As kindly recommended by Len I've tried changing line 59 from
system( "ip route add " . $localip . "/32 dev eth1" );
to
system( "route add " . $localip . "/32 dev eth1" );
instead of the previous error:
'ip' is not recognized as an internal or external command, operable
program or batch file. problem
connecting to "10.0.0.2", port 23: Unknown error at
c:\inetpub\wwwroot\perl\router_01.pl line 63
I get this error:
route: bad destination address 10.0.0.2/32
problem connecting to "10.0.0.2", port 23: Unknown error at
c:\inetpub\wwwroot\perl\router_01.pl line
63
Line 63 is:
$t = Net::Telnet->new( Timeout => 10, Prompt => '/> /', Host =>
$localip );
I'm happy running this script at the command prompt if that can work
reliably I was just trying it
internet explorer just because the active perl manual suggested running
its examples from
http://localhost/perl/ so under windows xp it seemed the logical choice
to try it in Internet
Explorer. The end result I would like is something that will run
continually all the time under
windows XP whenever the computer is switched on. Could you run this as
a service in someway or is
there a better way?
Thanks for all your help.
The Script now reads:
#! /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 = "10.0.0.2";
# 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) [I'm on a dynamic ip so
1st upstream ip changes from day to
# day so have put in 4.68.116.98 from further up the traceroute
# Your ISP's DNS servers: 212.159.13.49 & 212.159.13.50
# Your ISP's web server: 84.92.4.90
# i.root-servers.net: 192.36.148.17
# and any others you can think of
print "Content-type: text/html\n\n";
my @netips = ("194.166.128.72", "212.159.13.49", "212.159.13.50",
"84.92.4.90", "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( "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("admin", "epicrouter" ) 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";
}