1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Restart internet connection via batch?

Discussion in 'Tomato Firmware' started by eternal-blue, Jun 10, 2007.

  1. eternal-blue

    eternal-blue LI Guru Member

    Is it possible to disconnected and reconnect the pppoe connection with an batch command? (bat file like this: disconnect, wait 1 sec, connect new... ^^)
     
  2. roadkill

    roadkill Super Moderator Staff Member Member

    yes it's possible.... dd-wrt wiki has a script exactly for that should work on Tomato too...

     
  3. eternal-blue

    eternal-blue LI Guru Member

    thx, but what i have to make with this script? Looks like hieroglyphics for me ^^
     
  4. roadkill

    roadkill Super Moderator Staff Member Member

    this is for dhcp repair if you need a pppoe always on you can modify the script or find one that is already modified simply run it in the init section of Administration-> Scripts
     
  5. Overflow-ar

    Overflow-ar LI Guru Member

    Is this working??:confused:

    i'm facing a problem like once day, connection don't work anymore. And I cannot access modem page also (cablemodem), I just press Release and Renew on Status->Overview, and everything works again.

    How I may install this script? also, is there any chance this bricks my router? I got tomato 1.07

    Thanks for your time.
     
  6. gilladur

    gilladur Guest

    Same for me - your code is for use with the script function within the firmware or do I have to put this in a batch file, for using it as link on the desktop for example?

    I'm also looking for a batch like the codes which you can find for the fritzbox named like "reconnect.bat"

    thx in advance

    gilladur
     
  7. yaqui

    yaqui LI Guru Member

    Try this... place the script under administration>scripts>init and reboot your router... every 20 minutes it should shut down connection for 5 minutes (to avoid creating a multiple virtual connection) then reconnect:
    Code:
    sleep 5
    echo -e "#!/bin/sh\n while true \; do sleep 1200" > /tmp/wanrestart.sh
    echo -e "service wan stop" >> /tmp/wanrestart.sh
    echo -e "logger \'wan stop success\'" >> /tmp/wanrestart.sh
    echo -e "sleep 300" >> /tmp/wanrestart.sh
    echo -e "service wan start" >> /tmp/wanrestart.sh
    echo -e "logger \'wan restart successful\'" >> /tmp/wanrestart.sh
    echo -e "done" >> /tmp/wanrestart.sh
    chmod 755 /tmp/wanrestart.sh
    /tmp/wanrestart.sh
    Let me know if that works !
     
  8. Overflow-ar

    Overflow-ar LI Guru Member

    there is something really odd here, I bought the router some days ago, and flashed with tomato immediately.

    worked 3 days with not even one failure, but now every 4 o 6 hours just looses the connection, and stays that way until y press "release" and "renew" on the WAN.

    What could be wrong? is there any way I can ping to 192.168.100.1 ( my motorola suftboard 5100 ) and if there's no reply release and renew automatically?.

    thanks for your time
     
  9. yaqui

    yaqui LI Guru Member

    You need to do this to get access to your modem's interface: http://www.linksysinfo.org/forums/showthread.php?t=50437

    You might want to try a reconnect script, not sure why it would just be dropping you
     
  10. Overflow-ar

    Overflow-ar LI Guru Member

    not sure if I have been explicit, now, and most of the time I can connect to the modem web interface, but lately, something happends at about each 4 hours that makes my modem (surfboard s5100) loose the connection, the modem LEDs are off, even in upstream ranging, like something very odd were happening. ( or Ethernet cable were rip off). I cant even access modem interface at 192.168.1.1.

    I thought this was a router being hang, but nevertheless, the router is UP and working, so my guess is that DHCP expires, and router doesn't renew it until I do it manually. could this be?

    The solution is just enter router configuration, and release and renew DHCP manually for WAN interface, after that, everything is working fine for some hours. So I was asking if somebody faced the same problem, maybe there's an script that pings an IP each xxx interval, and if there's no response, just restart wan interface.


    thanks for your time.
     
  11. yaqui

    yaqui LI Guru Member

    Code:
    while true ; do /bin/sleep 1200
    /usr/bin/wget -O - http://google.com > /dev/null
    done
    
    Or some other smallish web site. The google page is currently about 5k.
    You might could use "/bin/ping -c 1 google.com > /dev/null" instead of the wget command, but some dialers ignore ping.
     
  12. Overflow-ar

    Overflow-ar LI Guru Member

    thanks yagui, I did not tested yet, but this I think I got the idea. :) , obviously I will replace google with my surfboard modem IP, and when it get no response, just restart WAN.

    One last question, this script quoted, is not restarting the WAN, right? What do I need to add to get this done?. This is by all means, unable to brick my router right? :confused:

    thanks for your time.
     
  13. yaqui

    yaqui LI Guru Member

    Maybe something similar to this:
    Code:
    logger WAN UP Script will execute after 30sec please wait.....
    sleep 30
    
    ## DEFINE VARIABLES
    surfboardip=<put your modem's ip here>
    pingtest=$(ping -c 1 $surfboardip | grep "from <put here your ip number from a ping result to your modem, keep the word from in front>")
    
    ## BEGIN TEST
    while [ -n "$pingtest" ] ; do /bin/sleep 1200
    if [ -n "$pingtest" ] ; then
      logger Ping $surfboardip SUCCESS
      continue 
    else
      break
      service wan stop
      sleep 120
      service wan start
    fi
    done
    
    You have to fill in the < ... > parts. I have no idea if that will work!! try at own risk... maybe some of the other scripting guys can look this over... any of you around?
     
  14. mstombs

    mstombs Network Guru Member

    I looked at this some time ago, but never got a complete solution, because my problem was with a half-bridge modem where you can always ping the modem but the problem is pinging the ISP gateway.

    You can lookup and use what the router has set as its gateway with

    Code:
    GW=$(nvram get wan_gateway)
    echo "Gateway=$GW"
    if ! ping -c 1 $GW ;then echo "Gateway not pingable";fi
    You can release/renew a WAN dhcp lease cleanly with some built in functions - I guess these are used by web screen buttons?

    Code:
    /sbin/dhcpc-release
    sleep 1
    /sbin/dhcpc-renew
    A problem I had was that if you detect a failure and release the IP it sometimes reverts to 0.0.0.0 which is the router itself and pingable, and you really want the script to only monitor when the WAN is supposed to be up and not interfere [$(nvram get wan_gateway_buf) may be useful?]. I would need to study in more detail exactly when wanup and firewall scripts are called - I favour the firewall script to start the monitoring...
     
  15. Overflow-ar

    Overflow-ar LI Guru Member

    Thanks for you all ! :biggrin:

    After some tests, I decided to get my hands dirty, afterall I'm studying Systems Engineering, I've mixed all the scripts around this topics and tested by doing a telnet, so in case something goes wrong, just reseting will avoid losing my router,

    here's the solution ! I've putted inside the "init" and seems it's written in nvram, cause i've restarted the router and surfboard several times, and connectivity goes up automatically :thumbup:

    Code:
    ## DEFINE VARIABLES
    surfboardip=192.168.100.1
    pingtest=$(ping -c 1 $surfboardip | grep "from 192.168.100.1")
    
    ## BEGIN TEST
    while [ true ]
    do 
    /bin/sleep 60
    if [ -n "$pingtest" ] ; then
      logger Ping $surfboardip SUCCESS
      continue 
    else
    /sbin/dhcpc-release
    sleep 1
    /sbin/dhcpc-renew
    logger automatic Wan Renew
    fi
    done
    
    so basically I was surprised with the break in the code posted by Yaqui, 'cause I wanted the script to be continuously checking to see if connectivity was up ALL THE TIME. Also mixed with Mstombs "release" and "renewal" cause I thought could be better than restarting the WAN, afterall this was what I was doing every 4 hours or so.

    Don't know how far may I push the 60 seconds sleep, to avoid lost internet but I think one minute is a pretty decent time without overwhelming the router with so many pings.

    I will keep posting to see how things go on in the next 4 hours :tongue:
     
  16. Overflow-ar

    Overflow-ar LI Guru Member

    Seems it renews every 60 seconds no matter what the pings says :S this is turning me mad :p

    i've modified the code a little bit, but now does not renew at all :(

    anyone could fix the IF issue? is not working right, i've tried with [-n "$pingtest"] but evaluates always false, i've tried with the sentences in telnet and worked fine, the output is generated only if there's response from the ping, but I cannot evaluate if's in Console (don't know why, just outputs > and does not respond at all at any given command after that )

    here's my slightly modified code ( which always evaluates true )

    Code:
    ## DEFINE VARIABLES
    surfboardip=192.168.100.1
    pingtest=$(ping -c 1 $surfboardip | grep "from 192.168.100.1")
    
    ## BEGIN TEST
    while [ true ]; do 
    /bin/sleep 60
    if [ "$pingtest"=="" ]; then
      logger Automatic WAN renew not needed
      continue 
    else
    /sbin/dhcpc-release
    sleep 1
    /sbin/dhcpc-renew
    logger Automatic WAN Renew
    fi
    done
    
     
  17. yaqui

    yaqui LI Guru Member

    This should fix it:
    Code:
    ## DEFINE VARIABLES
    surfboardip=192.168.100.1
    
    ## BEGIN TEST
    while [ true ]; do 
    /bin/sleep 60
    if ping -c 1 $surfboardip ; then
      logger Automatic WAN renew not needed
      continue 
    else
    /sbin/dhcpc-release
    sleep 1
    /sbin/dhcpc-renew
    logger Automatic WAN Renew
    fi
    done
    
    Thanks to mstombs!!
     
  18. Overflow-ar

    Overflow-ar LI Guru Member

    yes !! :clap2: :clap2: :clap2: :clap2: :clap2: now works perfectly :eek:nfire:

    Seriusly, thanks you all for all the time you've spent on this, now let's go buy a drink :drinking:
     
  19. bc82

    bc82 Guest

    html reconnect

    For other reconnect methods this is the html-code for disconnect and connect

    hxxp://admin:pASSWORD@ROUTERIP/service.cgi?_service=wan-stop&_redirect?status-overview.asp&sleep=2

    hxxp://admin:pASSWORD@ROUTERIP/service.cgi?_service=wan-restart&_redirect?status-overview.asp&sleep=5

    ------------------------------------
    Use http instead of hxxp and take your PASSWORD & ROUTERIP e.g. hxxp://admin:mypass@192.168.0.1/service.cgi?_service...


    With this code reconnect also works in programs like routercontrol

    Regards Steve
     
  20. yaqui

    yaqui LI Guru Member

    You might want to be careful with that if you are saving your password in your browser.. or if the browser is storing it on its' own.
     

Share This Page