Sign in to follow this  
Followers 0
ilkertezcan

Silent Router Restart

15 posts in this topic

I want restart of my INCA ADSL router modem in background and silent(one-clicked exe). I looked from console of modem and I selected/prepared this HTML page:

http://safirkare.googlepages.com/INCA_Modem_Restart.htm

This HTML page my router modem to restarting (disconnection) after modem login. I don't want always this html page run. I want silent runing an EXE file(one time).

I encountered AutoIt today. Very good program. How be this HTML to AU3 codes? I don't know. Are you may help? I'll be glad if you inform me about this.

HTML+Javascript code is simple:

FORM ACTION=http://192.168.1.1/cgi-bin/webcm

POST DATA

1) username: "login:command/username" + Submit

2) password: "login:command/password" + Submit

3) restart: "logic:command/reboot" + Submit

Note: I'm so sorry bad my english.

Share this post


Link to post
Share on other sites



What is the exact model name / number of this device? If it has telnet access this would be much easier to accomplish.

Share this post


Link to post
Share on other sites

Why not just use IE.au3? Should be easy too.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

My ADSL Modem model: INCA IM-204 ADSL 2/2+ ROUTER (Made for Turkey)

Console (192.168.1.1) similar to Motorola 2442 router. Similar page: http://www.angelfire.com/planet/mta2442/home.html

I can't login with telnet(Port 23 is opened). I dont understand to Telnet.

Router automatic to login: http://safirkare.googlepages.com/1_Login.htm

Router automatic to restart: http://safirkare.googlepages.com/2_Restart.htm

I combined to both page: http://safirkare.googlepages.com/INCA_Modem_Restart.htm

I tried IE Builder(IE3.au). This code don't working:

CODE
#include <IE.au3>

$oIE = _IECreate()

_IENavigate($oIE, "http://192.168.1.1")

$o_form = _IEFormGetObjByName($oIE, "f1")

$o_login = _IEFormElementGetObjByName($o_form, "login:command/username")

$o_password = _IEFormElementGetObjByName($o_form, "login:command/password")

$o_restart = _IEFormElementGetObjByName($o_form, "logic:command/reboot")

_IEFormElementSetValue($o_login, "admin")

_IEFormElementSetValue($o_password, "admin")

_IEFormElementSetValue($o_restart, "")

_IEFormSubmit($o_form)

Exit

I don't want to open from IE. I want to silent mode; no alert, no IE, no button, direct to restart. I think this possible. But I don't know AutoIt script.

Of course, I need you help.

Edited by ilkertezcan

Share this post


Link to post
Share on other sites

any info anyone can contribute on that subject will be helpful for me too... as i've been using a macro maker i've made to automate the reconnection of my router and as my other many users of that program - it's problematic that method!


[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Share this post


Link to post
Share on other sites

Once you get it working in IE.au3 you can make it invisible.

I'm guessing that there are items on the page being generated by javascript and you are using view source to get name...

Please use DebugBar (see my sig) to examine the page - your approach looks good.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Thanks to Armand & DaleHohm. I tried Debugbar and Macro Recording Tools. Both useful utiliy. Thanks.

I tried with wget, too. I succeeded reset my router. wget command-line:

CODE
wget -o nul http://192.168.1.1/cgi-bin/webcm --post-data="login:command/username=&login:command/password="

wget -o nul http://192.168.1.1/cgi-bin/webcm --post-data="logic:command/reboot"

As you can see, all element is post data string. another element no need.

Share this post


Link to post
Share on other sites

Kind of a punt, but you could use the RunWait() command to call your wget command line, and compile the resulting utility

if you persist in having problems getting your IE calls right.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

I don't want load to WGet. I think, reset post data very simple with "HTTP.au3". I written this code but don't working. <_< Where is error?

CODE

#include <HTTP.au3>

_HTTPConnect("192.168.1.1/cgi-bin/webcm")

_HTTPPost("192.168.1.1/cgi-bin/webcm", "login:command/username=&login:command/password=&logic:command/reboot")

Share this post


Link to post
Share on other sites

I don't want load to WGet. I think, reset post data very simple with "HTTP.au3". I written this code but don't working. <_< Where is error?

CODE

#include <HTTP.au3>

_HTTPConnect("192.168.1.1/cgi-bin/webcm")

_HTTPPost("192.168.1.1/cgi-bin/webcm", "login:command/username=&login:command/password=&logic:command/reboot")

HIIK. What errors if any are thrown?

why don't you just open your router for external admin access, post the ip , and let the forum debug. <lol>

When you can't go online b/c the router keeps reboting on you , check back. I'll have found the bug.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thank you flyingboyz. I succeded reset to router with AutoIt3! <_< This code working(from Hasher). Thanks to Hasher!

CODE
$sUrl = "http://192.168.1.1/cgi-bin/webcm"

$PostData = "login:command/username=&login:command/password="

$oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP")

$oHttpRequest.Open ("POST", $sUrl,True)

$oHttpRequest.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded")

$oHttpRequest.setRequestHeader ("Connection", "Keep-Alive")

$oHttpRequest.Send ($PostData)

sleep(1000)

$sUrl = "http://192.168.1.1/cgi-bin/webcm"

$PostData = "logic:command/reboot"

$oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP")

$oHttpRequest.Open ("POST", $sUrl,True)

$oHttpRequest.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded")

$oHttpRequest.setRequestHeader ("Connection", "Keep-Alive")

$oHttpRequest.Send ($PostData)

Waiting, waiting, waiting after Router reset. Show this alert box:

CODE

"Line -1:

Error: The requested action with this object has failed."

I think, Script waiting for response. No need response. Because reset made, disconnected. AutoIt3 making debug? I want exit/terminate immediately from script/program. Which command close to debug/alert/error box?

Edited by ilkertezcan

Share this post


Link to post
Share on other sites

if you want to trap the error, install a com error handler -- refer to the docs. this, properly done, will tell you

which call is generating the error (obviously it's a line of code after your reboot has ocurred), and you can start

taking a look at the pertinent code.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Look at using this:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 

; Performing a deliberate failure here (object does not exist)
$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.bogus 
if @error then Msgbox(0,"","the previous line got an error.")

Exit 


; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc

EDIT: That is an example of usage. There is a better one somewhere...

Add this into you script:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"COM Error Test","We intercepted a COM Error !"   & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description   & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "   & @TAB & $HexNumber        & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "   & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile   & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
  SetError(1); to check for after this function returns
Endfunc
Edited by Bert

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I added to script and this reporting:

Error Code

I succeeded close to error MsBox. No error box. <_<

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

(...)

Func MyErrFunc() 
if @error then Exit
Endfunc

Working proper but still waiting for exit. :)

Edited by ilkertezcan

Share this post


Link to post
Share on other sites

I found to "HttpRequest.setTimeouts" command of "MSXML2.ServerXMLHTTP". I reduced to timeout numbers. Thus worked.

This project successfully completed. <_< Thank you all...

Completed code:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$ResolveTimeout = 1
$ConnectTimeout = 1
$SendTimeout = 1
$ReceiveTimeout = 1

$sUrl = "http://192.168.1.1/cgi-bin/webcm"
$PostData = "login:command/username=&login:command/password="
$oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP")
$oHttpRequest.Open ("POST", $sUrl, False)
$oHttpRequest.setRequestHeader  ("Content-Type", "application/x-www-form-urlencoded") 
$oHttpRequest.setTimeouts (1, 1, 1, 1)
$oHttpRequest.Send ($PostData)

$sUrl = "http://192.168.1.1/cgi-bin/webcm"
$PostData = "logic:command/reboot"
$oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP")
$oHttpRequest.Open ("POST", $sUrl, False)
$oHttpRequest.setRequestHeader  ("Content-Type", "application/x-www-form-urlencoded") 
$oHttpRequest.setTimeouts (1, 1, 1, 1)
$oHttpRequest.Send ($PostData)

Func MyErrFunc() 
if @error then Exit
Endfunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0