Solved

Ping then post

Posted on 2002-07-17
7
209 Views
Last Modified: 2010-03-05
Hello,
I am totaly new to perl so please bear with me. What I am looking for is a way for my linux box to test/ping my connection at a set interval, and if it doesnt recieve a response to send a POST to my router that will tell it to reboot.

The code for the web page that launches the reboot is;
<FORM METHOD=POST ACTION="/reboot.html/set">
          <INPUT TYPE=submit NAME=reboot VALUE="Reboot">
          &nbsp;&nbsp;Are you sure? <INPUT TYPE=radio NAME=confirm VALUE=Yes >Yes
          <INPUT TYPE=radio NAME=confirm VALUE=No CHECKED>No
</FORM>

Any help will be much appreciated.
0
Comment
Question by:red_eye
  • 4
  • 3
7 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7160569
if your box does not respond to ping, how will you tell it to reboot? Has the router a dedicated connection (serial, or whatever) to the box?
0
 

Author Comment

by:red_eye
ID: 7160627
The Linux box and DSL router are on the same side of the connection e.g. they are both on my LAN. If the linux box tries to ping something on the internet and it fails then there is a good chance the router needs a reboot.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7160690
you still did not answer my question ...

Anyway, here as I would do it:

<FORM METHOD=POST ACTION="/ping.cgi">
 <INPUT TYPE=text   NAME=ip   VALUE="">
 <INPUT TYPE=submit NAME=ping VALUE="Ping">
</FORM>

when ping.cgi is called, it pings the given IP and returns a OK page:

<H2>Ping "ip" successful</H2>

or another form if the ping failed:

<FORM METHOD=POST ACTION="/reboot.cgi">
  <INPUT TYPE=submit NAME=reboot VALUE="Reboot">
  Are you sure?
  <INPUT TYPE=radio NAME=confirm VALUE=Yes >Yes
  <INPUT TYPE=radio NAME=confirm VALUE=No CHECKED>No
</FORM>

when reboot.cgi is called, it reboots what ever you want by issiung the approriate command.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:red_eye
ID: 7160722
Sorry I'm not making myself clear. The router, an efficient SpeedStream 5660 has a web interface. From the web interface it can be rebooted. It is connected via ethernet to a D-Link etherswitch. The Linux box is also connected to the etherswitch. So when my WAN/Internet connection is down the Router and Linux box are still connected on my LAN via ethernet. I want a script written in perl to run on the linux box, it should ping the internet and if there is no response to the pin then it should execute the Post method using the following data;

<FORM METHOD=POST ACTION="/reboot.html/set">
         <INPUT TYPE=submit NAME=reboot VALUE="Reboot">
         Are you sure? <INPUT TYPE=radio NAME=confirm VALUE=Yes >Yes
         </FORM>

In other words I want my Linux box when it doesnt find the connection to be up to push the peboot button on my router. A sample of the page I see in my router that I can reboot it from is at;
http://www.pcsites.com/sample/reboot.html

When I access my router via its intergrated web interface if I choose yes on that screen and click on the reboot button the router does a warm reboot.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 total points
ID: 7160761
# push the reboot button:
wget 'http://your-router/reboot.html/set?confirm=Yes&reboot=Reboot'

If you wan to check the response of the router, see man wget, probably the -O option
0
 

Author Comment

by:red_eye
ID: 7160776
That worked perfectly now all I need to do is script the rest. Thanks.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7160801
good luck.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expect & sshpass package for Solaris 10 x86 15 922
Perl Sort Question 4 135
Replace  text in a file 2 109
Using Perl DBI to query oracle 3 43
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question