restart wifi on an asus router

Posted on
Fri Aug 22, 2014 11:15 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

restart wifi on an asus router

sometimes wifi is slowing down on the router and a restart brings it back to normal (very good) performance

this applescript can be executed in an action group/type:server action/ script and file action/ execute script .
Copy and paste the applescript code there and change the userid, password, ip number of the router.
then execute the action script and the router will reset its wifi

Should work for ASUS 5x 6x 7x, they share the same code base

you could execute the wifiRestart manually by
open terminal
telnet routeripnumber
enter userid
enter password
type at the router prompt: /sbin/restart_wireless



Karl


Code: Select all
-- Karl Wachs
-- Aug 22 2014
-- version 1.1
-- applescript
--
-- ========>   restart Asus WiFi using expect commands
--
--
set lf to ASCII character 10
set theRouterID to "therouteruseridhere"
set theRouterPassword to "therouterpasswordhere"
set theRouterIPNumber to "therouteripnumberhere"
set theR to "\\" & "\\" & "r"
set userName to short user name of (system info)
set theScriptFile to "/users/" & userName & "/Documents/scripts/resetwifi"
set theCommandrestartWireless to "/sbin/restart_wireless" -- this is the command to resetra wireless


-- create shell script with "expect" commands   
do shell script "echo \"#!/usr/bin/expect\"  > " & theScriptFile
do shell script "echo 'set theReturn " & theR & "  ' >>  " & theScriptFile
do shell script "echo 'set timeout 20  ' >>  " & theScriptFile
do shell script "echo 'set ipNnumber [lindex $argv 0 ] ' >> " & theScriptFile
do shell script "echo 'set userID [lindex $argv 1 ]' >> " & theScriptFile
do shell script "echo 'set password [lindex $argv 2 ]' >> " & theScriptFile
do shell script "echo 'set routerCommand [lindex $argv 3 ]' >> " & theScriptFile
do shell script "echo 'spawn telnet $ipNnumber '  >> " & theScriptFile
do shell script "echo 'expect \"*?ogin:\" {  send \"$userID$theReturn\" }' >> " & theScriptFile
do shell script "echo 'expect \"*?assword:\" {  send \"$password$theReturn\" }' >> " & theScriptFile
do shell script "echo 'expect \"*?#\" {send \"$theReturn\" }' >> " & theScriptFile
do shell script "echo 'expect \"*?#\" {send \"$routerCommand$theReturn\"  }'>> " & theScriptFile
do shell script "echo 'expect \"*?#\" {send \"$theReturn\"  }'>> " & theScriptFile
-- make it executable
do shell script "chmod +x " & theScriptFile
-- execute it
do shell script theScriptFile & " " & theRouterIPNumber & " " & theRouterID & " " & theRouterPassword & " " & theCommandrestartWireless & "&"


will create the following "expect file in /users/yourid/documents/script" (that directory must exist):
Code: Select all
#!/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"  }


and execute it (last line

...
you could execute the shell script once it is created in a terminal or in indigo with python or shell script..

Posted on
Fri Aug 22, 2014 2:17 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: restart wifi on an asus router

And here the same thing in python...

Code: Select all
#--
#-- ========>   restart Asus WiFi using shell script and expect commands
#--
#--
import subprocess
import os

theRouterID = "therouterpassword"
theRouterPassword = "therouterpassword"
theRouterIPNumber = "therouteripnumber"
userName = "yourmacusername"
theScriptDir = "/users/" + userName + "/Documents/scripts/"
theScriptFile = theScriptDir+"resetAsusWiFi.sh"
theCommandrestartWireless = "/sbin/restart_wireless" # this is the command to reset wifi
if not os.path.exists(theScriptDir):
    os.makedirs(theScriptDir)

#-- create shell script with "expect" commands   
f= open( theScriptFile , "w")
f.write('#!/usr/bin/expect \n' )
f.write('set theReturn  \\r  \n'  )
f.write('set timeout 20  \n')
f.write('set ipNnumber [lindex $argv 0 ] \n'  )
f.write('set userID [lindex $argv 1 ]\n'  )
f.write('set password [lindex $argv 2 ]\n'  )
f.write('set routerCommand [lindex $argv 3 ]\n'  )
f.write('spawn telnet $ipNnumber \n'   )
f.write('expect \"*?ogin:\" {  send \"$userID$theReturn\" }\n'  )
f.write('expect \"*?assword:\" {  send \"$password$theReturn\" }\n'  )
f.write('expect \"*?#\" {send \"$theReturn\" }\n'  )
f.write('expect \"*?#\" {send \"$routerCommand$theReturn\"  }\n' )
f.write('expect \"*?#\" {send \"$theReturn\"  }\n' )
f.close()

subprocess.Popen("chmod +x " + theScriptFile ,shell=True)
subprocess.Popen(theScriptFile +" " + theRouterIPNumber + " " + theRouterID + " "+ theRouterPassword + " " + theCommandrestartWireless +" > /dev/null  2>&1 &",shell=True)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests

cron