What's new

WAN connect and disconnect using script

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

perla

New Around Here
Hello everyone!

First of all, thank you Merlin for the great work and firmware!

I would like to ask for some help.
My question: Is it possible to connect/disconnect to/from the Internet by using a script?

I'm asking this because I have got a creepy cable modem. Twice or three times a day it does a restart (I think it looses the signal) and my Internet connection interrupts. My problem is that my router doesn't detect this restart and because I am using dynamic IP it doesn't initiate a reconnect automatically. I have to manually disconnect and then connect (through the admin page of the router) to have my Internet connection working again.

I think the perfect solution would be if I wrote a script that pings a webpage every 5 minutes (by using cron) and if the ping fails then it does an automatic disconnect and connect on the WAN interface.
Is it possible to write such a script? Can anybody help me in this?

Thank you very much for the help in advance.
 
I did a small investigation regarding how the connect and disconnect command is sent to the router when the user is using the admin page.

The command is sent by using a POST request to the following page: /start_apply2.htm
The requested status (on/off) of the WAN interface is in the following form: name=internetForm
Input field: name=wan_enable; value = 1 or 0

Is it possible to generate this kind of POST request (containing the requested WAN status in the wan_enable field) by using wget?

I can not belive that there is no way to reach this WAN status changing feature by using a simple function call available in the firmware...
 
My *nix is pretty rusty, so forgive me if this is way off. But shouldn't this be as simple as

Code:
ifconfig eth0 down
sleep 5
ifconfig eth0 up
 
Code:
service restart_wan
 
Hello.
Where do I type this one please?
Can one in a batch file?

Thank you
 
You have to connect to the router through either SSH or Telnet, and type that command on the command line.
 
Thanks RMerlin!

I will test this command on the weekend to see if it can solve my problem.
However, according to HorstG question, I hope that this command will also work in a batch file called by a cronjob.
 
Thanks RMerlin!

I will test this command on the weekend to see if it can solve my problem.
However, according to HorstG question, I hope that this command will also work in a batch file called by a cronjob.

Sure. Any shell command can also be run through a cron job or a shell script.
 
Hi Merlin
Do you have maybe a tutorial to create a reconnect cronjob?

It is very difficult for me with English.

Thank you

Horst
 
Hi Merlin
Do you have maybe a tutorial to create a reconnect cronjob?

It is very difficult for me with English.

Thank you

Horst

There are instructions on the Github Wiki. I also posted more details on how to configure it in various posts on these forums - try a forum search on "cronjob" or something like that.
 
Hi I have searched the forums and cron job but because my English is very bad
I could not find anything real. Can send me the links or a guide please someone?
Is it possible éventuel via batch file?

Thanks again Horst
 
@RMerlin
how to trigger a wan reconnect with curl?
thanks

You can't. There's no public REST API, as those are nothing but security nightmares anyway (ask Linksys...).
 
Mmmm... not sure what's happening here...
I'm trying to use service command in a batch script to restart wan when pyload needs a new IP address.
service restart_wan works fine if used with putty, but if I run a basic .sh script:

Code:
#!/bin/sh
service restart_wan

this is the result:

Code:
-sh: ./: Permission denied
 
Make it executable:

Code:
chmod a+rx script.sh
 
Thanks for your replies, file is created by nano, but the problem was in cut/paste from Windows...
 
@RMerlin
and with the UPNP urn schemas is possible to trigger a reconnect?
i need a command to execute a wan ip change from windows.
thanks

No idea, but if there were, I'd consider that a security hole in needs of fixing, since UPnP is completely unauthenticated.
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top