Jump to content
Sign in to follow this  
mikeytown2

Reset Router with POST

Recommended Posts

mikeytown2

I have a very cheap Access Point/Router (Trendnet - TEW-432BRP). The wireless gateway stops working after some time, reseting it works. I have a wireless link between this and my Linksys WRT54G running DD-WRT. Using this script I reset my Trendnet router when the wireless link fails.

;Load http.au3
#include "HTTP.au3"

;Set Parameters
$RemoteIP = "192.168.3.2"
$LocalIP = "192.168.3.1"
$TelnetPort = 23
$SleepTime = 15 * 60 * 1000 ;15 minutes
$ResetTime = 5 ;reset router at 5am
$ResetBool = False
Opt("TrayIconHide", 1)
Opt("TrayIconDebug", 1) 

;Run Loop
While 1
    ;Reset Router at the time set no matter what
    If @HOUR == $ResetTime And $ResetBool == False Then
        ResetRouter($LocalIP)
        $ResetBool = True
    Else
        $ResetBool = False
    EndIf
    Sleep(60 * 1000) ; wait one minute
    
    ;Check Wireless Connection
    $RemoteConnectionOK = CheckRemoteRouter($RemoteIP, $TelnetPort)
    If Not $RemoteConnectionOK Then
        ResetRouter($LocalIP)
    EndIf
    
    ;Put Program To Sleep
    Sleep($SleepTime)
WEnd


Func ResetRouter($IP)
    $host = "http://" & $IP & "/"
    $page = "/restart.cgi"
    $data = "restart=Restart"
    $socket = _HTTPConnect($IP)
    _HTTPPost($host, $page, $socket, $data, "admin", "admin")
EndFunc   ;==>ResetRouter

Func CheckRemoteRouter($IP, $Port)
    TCPStartup()
    $socket = TCPConnect($IP, $Port)
    TCPShutdown()
    If $socket = -1 Then
        Return False ;connection bad
    Else
        Return True ;connection good
    EndIf
EndFunc   ;==>CheckRemoteRouter

Get #include "HTTP.au3" from here, with my mod at the last post.

http://www.autoitscript.com/forum/index.php?showtopic=29631

http://www.autoitscript.com/forum/index.ph...mp;#entry601371

  • Like 1

Share this post


Link to post
Share on other sites
spudw2k

Share this post


Link to post
Share on other sites
mikeytown2

Share this post


Link to post
Share on other sites
Armand

nice, I'll add it to my Reconnection utility.... :mellow:


[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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.