Sign in to follow this  
Followers 0
GtaSpider

Netgear Router ReConnect

7 posts in this topic

#1 ·  Posted (edited)

Hello

This Script will Automatically reconnect your Netgear Router.

THIS PROGRAM IS ONLY TESTED WITH NETGEAR ROUTER AND IT'S BETA

I've tested it with Netgear dg834B, dg834GB and dgb111PNB

You Need PaulIA's Auto3Lib to run the Sourcecode.

Thanks to PaulIA (Auto3Lib) and lod3n (PNG Support example)

In the attached ZIP you'll find the Pictures and the Compiled exe.

The ZIP file: DOWNLOAD

Here is the code:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=server_connection.ico
#AutoIt3Wrapper_outfile=Router ReConnect.exe
#AutoIt3Wrapper_Compression=3
#AutoIt3Wrapper_Res_Comment=Router ReConnect ist nur für Netgear Router!
#AutoIt3Wrapper_Res_Description=Trennt und wiederverbindet Netgear Router
#AutoIt3Wrapper_Res_Fileversion=0.9.5.0
#AutoIt3Wrapper_Res_LegalCopyright=GtaSpider
#AutoIt3Wrapper_Res_Language=1031
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;AutoIt Versions Check
If Number(StringReplace(@AutoItVersion, ".", "")) < 3281 Then _ErrorMsg ("Das Skript funktioniert möglicherweise nicht mit Ihrer AutoIt Version!" & @CRLF & "Wollen Sie es trozdem starten?", 0, 52)
    
;Includes
#include <A3LGDIPlus.au3>
#include <A3LScreenCap.au3>
#include <inet.au3>
#include <ie.au3>
#include <string.au3>

;FileInstalls
DirCreate(@TempDir&"\Rout~")
FileInstall("AeroTemplate.png",@TempDir&"\Rout~\AeroTemplate.png",1)
FileInstall("master07_background.jpg",@TempDir&"\Rout~\master07_background.jpg",1)
FileInstall("grey.gif",@TempDir&"\Rout~\grey.gif",1)

;Globals
Global Const $AC_SRC_ALPHA = 1
Global Const $ULW_ALPHA = 2
Global Const $ProgramVersion = "0.9.5beta" 
Global $old_string = "", $runthis = ""
Global $launchDir = @DesktopDir
Global $Username = RegRead("HKEY_CURRENT_USER\Software\Router ReConnect", "Username")
Global $Userpassword = _StringEncrypt(0, RegRead("HKEY_CURRENT_USER\Software\Router ReConnect", "Userpassword"), "RoUReC3%'§^'", 2)
Global $RouterAdress = RegRead("HKEY_CURRENT_USER\Software\Router ReConnect", "Router Adress")

;Windows Version Check
IF @OSVersion <> "WIN_XP" Then _ErrorMsg("Das Skript funktioniert möglicherweise nicht mit Ihrem Betriebssystem!"&@CRLF&"Das Program wurde für Windows XP erstellt, Sie haben Windows "&Stringupper(StringTrimLeft(@OSVersion,4))&"."&@CRLF&"Wollen Sie es trozdem starten?",0,52)
    
;GDI Startup
_GDIP_Startup ()
$pngSrc = @TempDir&"\Rout~\AeroTemplate.png" 
If Not FileExists($pngSrc) Then _ErrorMsg ("Die Datei " & $pngSrc & " Existiert nicht, Programm wird beendet", 1, 16)
$hImage = _GDIP_ImageLoadFromFile ($pngSrc)


$width = _GDIP_ImageGetWidth ($hImage)
$height = _GDIP_ImageGetHeight ($hImage)

;Falls RegDaten nicht vorhanden, erstellen.
If $Username = '' Or $Userpassword = '' Or $RouterAdress = '' Then

    $guiUserdata = GUICreate("Router ReConnect v" & $ProgramVersion & " - By GtaSpider", 295, 183, 207, 141, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
    GUICtrlCreatePic(@TempDir&"\Rout~\master07_background.jpg", -16, -40, 534, 400)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateLabel("Router Adresse:", 160, 16, 80, 15)
    GUICtrlSetBkColor(-1, -2)
    $inpRouterAdress = GUICtrlCreateInput("www.Routerlogin.com", 160, 32, 121, 21)
    GUICtrlCreateLabel("Username:", 160, 56, 55, 15)
    GUICtrlSetBkColor(-1, -2)
    $inpUsername = GUICtrlCreateInput("admin", 160, 72, 121, 21)
    GUICtrlCreateLabel("Passwort:", 160, 96, 50, 15)
    GUICtrlSetBkColor(-1, -2)
    $inpUserpassword = GUICtrlCreateInput("", 160, 112, 121, 21, $ES_PASSWORD)
    $butNext = GUICtrlCreateButton("&Weiter", 160, 138, 121, 25, $BS_DEFPUSHBUTTON)
    GUISetState()
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            CAse $butNext
                RegWrite("HKEY_CURRENT_USER\Software\Router ReConnect", "Username","REG_SZ",GUICtrlRead($inpUsername))
                RegWrite("HKEY_CURRENT_USER\Software\Router ReConnect", "Userpassword","REG_SZ",_StringEncrypt(1,GUICtrlRead($inpUserpassword), "RoUReC3%'§^'", 2))
                RegWrite("HKEY_CURRENT_USER\Software\Router ReConnect", "Router Adress","REG_SZ",StringLower(StringReplace(GUICtrlRead($inpRouterAdress),"http:\\","")))
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
    Global $Username = RegRead("HKEY_CURRENT_USER\Software\Router ReConnect", "Username")
    Global $Userpassword = _StringEncrypt(0, RegRead("HKEY_CURRENT_USER\Software\Router ReConnect", "Userpassword"), "RoUReC3%'§^'", 2)
    Global $RouterAdress = RegRead("HKEY_CURRENT_USER\Software\Router ReConnect", "Router Adress")
EndIf



;PNG Gui
$GUI = GUICreate("Router ReConnect", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
SetBitmap ($GUI, $hImage, 0)
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

GUISetState()
$hBMP = _ScreenCap_Capture (@TempDir & "\Rout~\wg.jpg", 0, 0, @DesktopWidth, @DesktopHeight, False)
WinSetOnTop($GUI, "", 1)

For $i = 0 To 255 Step 10
    SetBitmap ($GUI, $hImage, $i)
Next

;Control GUI
$controlGui = GUICreate($ProgramVersion, $width, $height, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI)

GUICtrlCreatePic(@TempDir&"\Rout~\grey.gif", 0, 0, $width, $height)
GUICtrlSetState(-1, $GUI_DISABLE)
$dellab = GUICtrlCreateLabel("Please Wait...", 140, 10, 400, 40)

GUICtrlSetFont(-1, 20, 800)
GUICtrlSetBkColor(-1, -2)
GUISetState()


SplashImageOn("", @TempDir & "\Rout~\wg.jpg", @DesktopWidth, @DesktopHeight, 0, 0, 1)
WinSetOnTop($controlGui, "", 1)
Global Const $MomentaryIP = _GetIP()
;Zum Router wird Verbunden
$oIE = _IECreate($RouterAdress, 0, 0, 0)
WinWait("Verbindung zu "&$RouterAdress&" herstellen", "", 7)
ControlSetText("Verbindung zu "&$RouterAdress&" herstellen", "", 1003, $Username)
ControlSetText("Verbindung zu "&$RouterAdress&" herstellen", "", 1005, $Userpassword)
ControlClick("Verbindung zu "&$RouterAdress&" herstellen", "", 1)
SplashOff()

GUISetState(@SW_HIDE)

GUICtrlDelete($dellab)
GUICtrlCreateLabel("Momentary IP:", 50, 20, 120)
GUICtrlSetFont(-1, 12, 800)
GUICtrlSetBkColor(-1, -2)
GUICtrlCreateLabel("New IP:", 103, 45, 70)
GUICtrlSetFont(-1, 12, 800)
GUICtrlSetBkColor(-1, -2)
GUICtrlCreateInput($MomentaryIP, 170, 20, 150, 22, $ES_READONLY)
GUICtrlSetFont(-1, 12, 800)
$newipinp = GUICtrlCreateInput("xxx.xxx.xxx.xxx", 170, 45, 150, 22, $ES_READONLY)
GUICtrlSetFont(-1, 12, 800)
GUICtrlCreateButton("By GtaSpider", 50, 70, 270, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$prog = GUICtrlCreateProgress(50, 97, 650, 17)
$Edit = GUICtrlCreateEdit("", 330, 20, 370, 75)

GUISetState()

GUICtrlSetData($prog, 10)
GUICtrlSetData($Edit, "Zum Router Verbunden" & @CRLF, 1)
_IELoadWait($oIE);Warten bis Routerseite komplett geladen
GUICtrlSetData($prog, 15)
GUICtrlSetData($Edit, "Routerseite komplett geladen" & @CRLF, 1)
GUICtrlSetData($prog, 20)
GUICtrlSetData($Edit, "Versuche Router zu trennen" & @CRLF, 1)
_IENavigate($oIE, "http://"&$RouterAdress&"/setup.cgi?todo=disconnect");Trennt Router
GUICtrlSetData($prog, 30)
GUICtrlSetData($Edit, "Der Router wurde getrennt!" & @CRLF, 1)
For $i = 30 To 90 Step 5
    $ping = Ping("www.google.de", 100);Pingt google an, bis kein error
    $ping = @error
    If Not $ping Then ExitLoop
    GUICtrlSetData($prog, $i)
    GUICtrlSetData($Edit, "Ping Versuch gescheitert, Errorcode: " & $ping & " " & $i & "%" & @CRLF, 1)
Next
If $i = 90 And $ping Then
    While $ping
        Ping("www.google.de", 100)
        $ping = @error
        GUICtrlSetData($Edit, "Ping Versuch gescheitert, Errorcode: " & $ping & "%: " & Random(90, 99, 1) & @CRLF, 1)
    WEnd
EndIf
GUICtrlSetData($prog, 90)
GUICtrlSetData($Edit, "Ping Versuch erfolgreich" & @CRLF, 1)
GUICtrlSetData($Edit, "Lese neue IP ein" & @CRLF, 1)
$newip = -1
While $newip = -1
    $newip = _GetIP();Lese neue IP ein bis $newip <> -1
WEnd
GUICtrlSetData($newipinp, $newip)
If $newip <> $MomentaryIP Then
    GUICtrlSetData($prog, 100)
    GUICtrlSetData($Edit, "Router wurde erfolgreich ReConnected!" & @CRLF, 1)
    GUICtrlSetData($Edit, "                                              By GtaSpider" & @CRLF, 1)
    GUICtrlSetBkColor($Edit, 0x00ff00)
Else
    GUICtrlSetData($prog, 0)
    GUICtrlSetData($Edit, "Router wurde NICHT erfolgreich ReConnected!" & @CRLF, 1)
    GUICtrlSetData($Edit, "Neustart des Programmes erfolgt in 5" & @CRLF, 1)
    GUICtrlSetBkColor($Edit, 0xff0000)
    For $i = 4 To 0 Step - 1
        Sleep(1000)
        GUICtrlSetData($Edit, "Neustart des Programmes erfolgt in " & $i & @CRLF, 1)
    Next
    RunWait('"' & @ComSpec & '" /c "' & @ScriptFullPath & '"', '', @SW_HIDE)
    Exit
EndIf

Sleep(5000)

GUIDelete($controlGui)
For $i = 255 To 0 Step - 5
    SetBitmap ($GUI, $hImage, $i)
Next




;Funktionen
Func OnAutoItExit ()
    If IsDeclared("hImage") Then _API_DeleteObject ($hImage)
    _GDIP_Shutdown ()
    If IsDeclared("oIE") Then _IEQuit($oIE)
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n 3 127.0.0.1' & @CRLF _
            & 'del /F /S /Q "'&@TempDir&'\Rout~" > nul' & @CRLF _
            & 'del ' & @TempDir & '\scratch.bat'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir)
EndFunc   ;==>OnAutoItExit

Func _ErrorMsg ($sText, $iExit = 1, $iMsgOpt = 48)
    If MsgBox($iMsgOpt, "Warnung - Router ReConnect v" & $ProgramVersion, $sText) = 7 Or $iExit = 1 Then Exit
EndFunc   ;==>_ErrorMsg



Func WM_NCHITTEST ($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST


Func SetBitmap ($hGUI, $hImage, $iOpacity)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

    $hScrDC = _API_GetDC (0)
    $hMemDC = _API_CreateCompatibleDC ($hScrDC)
    $hBitmap = _GDIP_BitmapCreateHBITMAPFromBitmap ($hImage)
    $hOld = _API_SelectObject ($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIP_ImageGetWidth ($hImage))
    DllStructSetData($tSize, "Y", _GDIP_ImageGetHeight ($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
    _API_UpdateLayeredWindow ($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _API_ReleaseDC (0, $hScrDC)
    _API_SelectObject ($hMemDC, $hOld)
    _API_DeleteObject ($hBitmap)
    _API_DeleteDC ($hMemDC)
EndFunc   ;==>SetBitmap

Mfg / Best Regars Spider

Edited by GtaSpider

www.AutoIt.de - Moderator of the German AutoIt Froum

Share this post


Link to post
Share on other sites



AWESOME! This will save me a lot of time having to reconnect my netgear router, mine seems to go out alot. :)

Share this post


Link to post
Share on other sites

Hello

Thank you :) it makes me happy, that this is not completely useless!

Mfg / Best regards


www.AutoIt.de - Moderator of the German AutoIt Froum

Share this post


Link to post
Share on other sites

will be testing on Netgear DIR-615 with win xp pro


[center][/center]

Share this post


Link to post
Share on other sites

its a no go for me... besides i don't know this language either.... but looks very nice...


[center][/center]

Share this post


Link to post
Share on other sites

Hello

Yes, Sorry. I work on a language fix (German to English) This version works only for IE 6 or worser.. Next version will work for Vista and IE 7, too.

Mfg / BEst Regards Spider


www.AutoIt.de - Moderator of the German AutoIt Froum

Share this post


Link to post
Share on other sites

im using IE 6.... xp pro service pack two with no updates... but i got my router a month ago its a, oh wait thats right im not using the netgear i switched to D-link.... and i got rid of the linksys too... i feel so stupid.... Im used to having three networks two G and one N, i just didnt need three routers so i only kept the N. Well it looked like a really nice script though, good work!'


[center][/center]

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