Applescript to Shut Down Asante Router

The Asante Accelerated Router (FR5000 series) uses a web interface for access to maintenance and commands for the unit. I’m looking for some applescript to automatically login, fill in the web form with the parameters to shut the unit down, and finally select the button to initiate this gentle shutdown. This is so I can shut the router down automatically during an extended power outage in conjuction with the UPS software shutting off the computer. Hints on how I can script this would be greatly appreciated.

voltar

Web interface?
Then, theorically, you can send-retrieve data through “URL Access Scripting”.
You must take a look to the HTML code, then build your own url. Eg, in a form with ACTION=“http://192.168.200.255/login”, which has a text field and a password field (named “user” and “password”), you can build the following URL:

tell app "URL Access Scripting"
   download "http://192.168.200.255/login?user=voltar&password=nickipicki" to (choose file name)
end tell

Just an example… :slight_smile:

JJ,

Thanks for the suggestion. I’m not downloading anything just posting replies to blank fields. Are there send, post, transmit, or execute like commands in applescript that allow simulated keyboard responses to web based forms? BTW, these web forms are presented from the router and I don’t have any way of modifying these.

voltar

The main goal of the code I posted was not download a page, but send to the router some instructions: “action → login | user → x | password → y” and “download” is the propper syntax to do it through “URL Access Scripting”.
Another eg:

tell app "URL Access Scripting" 
   download "http://www.google.com/search?q=macscripter" to (choose file name) 
end tell

This will send “google.com” the instruction “search for macscripter” (and also, of course, you will download the response). So, for the server (google, router), this will be the same as if you manually go to google’s main page, fill a text field with “macscripter”, then press the submit button. The browser will create “on-the-fly” the propper url “http://www.google.com/search?q=macscripter” and it will call google’s method “search” (or router’s one “login” or whatever is called).
If you prefer it, you can also call this method without “URL Access Scripting” and without downloading data, and display the result in a web page:

open location "http://192.168.200.255/login?user=voltar&password=nickipicki"

Here, the browser will display the results of action “login” at host “192.168.200.255” (eg. your router’s IP): login successful, shutdown ok, whatever failed…

Also, of course, you can use Internet Explorer to do it via GUI, filling forms helped by “do script” IE’s command (execute javascript code):

tell app "Internet Explorer"
	do script "document.forms[0].elements[0].value='my user name'"
end tell

This code (if you open a page with a form in Internet Explorer) will “type” the string “my user name” it the first element of the first form. A working sample: open IE, open “http://www.google.com/”, execute this code:

tell application "Internet Explorer"
	do script "with(document.forms[0]) {
	elements[0].value='macscripter'
	submit();
}"
end tell

Voilá!
But I think the best way (quick, secure, nearly invisible) is through UAS :wink:

You can! Try this: open google and execute:

set thescript to "
function hey(t){
	window.alert(t)
}
document.bgColor='000000';document.fgColor='FFFFFF';document.linkColor='FF0000';
with(document.forms[0]){
	elements[2].value='what the heck i\'m doing here?'
	elements[3].value=' To Search Or Not To Search ';
	elements[4].value='Please, kick me!';
	action='java'+'script:hey(\'arrrrgHHH\')';
}
"
tell application "Internet Explorer"
	do script thescript
end tell
  • This may work depending on your “preferences” at Google