reboot / re-lease dhcp asus router through shell script

Posted on
Tue Jan 21, 2014 1:16 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

reboot / re-lease dhcp asus router through shell script

don't know if anyone is interested .. not directly an indigo item, but you could use this to reboot or force a re-lease of the routers public ip number in indigo if your internet connection hangs.


with the attached code and
and with the following command the router will re-lease its IP number:
./telnettorouter.sh routeripnumber admin yourrouterpassword /sbin/udhcpc
ie:
./telnettorouter.sh 192.168.1.1 admin abc123 /sbin/udhcpc
if the ip number of the router is 192.168.1.1 and the router password is abc123

and with the following command the router will reboot:
./telnettorouter.sh routeripnumber admin yourrouterpassword /sbin/reboot

this works for an ASUS RT-AC68U **), most likely works for most newer ASUS roter models.
*) the ASUS userid is hardwired to be admin
**) this one supports 2 WAN connections and automatic switching if you have 2 internet providers..

Karl


ps with

instead of /sbin/reboot your could use :
"cat /tmp/syslog.log | grep -v 'Dec 31' | grep -v '192.168' | grep ' dhcp ' | tail -1"
to get the last dhcp record that shows the current IP number and the ip number of the first router on the internet:
Jan 21 00:52:39 dhcp client: bound 71.11.216.221 via 71.11.216.1 during 20479 seconds.


Code: Select all
###  save this file to your disk, with  filename  telnettorouter.sh  and  delete this line from the file and do a  "chmod +x telnettorouter.sh" to enable execution
#!/usr/bin/expect
set theReturn \r 
set timeout 20 
set ipNnumber [lindex $argv 0 ]
set userID [lindex $argv 1 ]
set password [lindex $argv 2 ]
set routerCommand [lindex $argv 3 ]
spawn telnet $ipNnumber
expect "*?ogin:" {  send "$userID$theReturn" }
expect "*?assword:" {  send "$password$theReturn" }
expect "*?#" {send "$theReturn" }
expect "*?#" {send "$routerCommand$theReturn"  }
expect "*?#" {send "$theReturn"  }
Last edited by kw123 on Tue Jan 21, 2014 10:41 am, edited 1 time in total.

Posted on
Tue Jan 21, 2014 9:53 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: reboot / re-lease dhcp asus router through shell script

Thanks for the contribution, I'm sure others will find it useful.

I moved it to a more appropriate forum - where people are more likely to find it in the future.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest