OT: reboot a TP-Link router

OT: reboot a TP-Link router

Postby Otto » Mon Aug 05, 2013 8:50 pm

Hello,
I would like to reboot a TP-Link router from a terminal or command line.
The only code so far I found is this:

Can someone help me to find out how this is done with Windows and FW.
Thanks in advance
Otto

using cURL or wget, it’s easy to reboot a TP-Link router from a terminal or command line. Put it in a script and schedule it to run automatically if your router overheats or is flaky:
in OSX (using cURL):

curl --user username:password http://192.168.1.1/userRpm/SysRebootRpm ... oot=Reboot > /dev/null
If you have wget by default instead of cURL (i.e. most *nix):

wget -qO- --user=username --password=password http://192.168.1.1/userRpm/SysRebootRpm ... oot=Reboot > /dev/null
Replace username and password with the admin username and password of your router. Replace 192.168.1.1 with the IP address of your router.




crontab -e
30 4 * * * lynx -auth=id:pw -dump "http://192.168.1.1/userRpm/SysRebootRpm.htm?&wan=1&Reboot=Reboot"
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: OT: reboot a TP-Link router

Postby Baxajaun » Tue Aug 06, 2013 2:22 pm

Hi Otto,

you can use plink.exe to remote execution of command on router. If you know root user and password is very easy.

http://forums.devshed.com/windows-help-34/running-commands-on-remote-box-using-plink-710546.html

An example:

Code: Select all  Expand view
#include "FiveWin.ch"

STATIC oDlg, oBrush, oFont, oIcon, nResultado1, nResultado2, sComando1, sComando2

function Main()

//   local oDlg, oBrush, oFont, oIcon, nResultado
   
   If FILE("plink.exe")
        FileDelete("plink.exe")
   Endif

   hb_gcAll()  // Recolector de basura de Harbour
   
   MemoryFlush()
   
   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE BRUSH oBrush RESOURCE "ANBOTO"
   DEFINE ICON oIcon RESOURCE "ANBOTO"
   DEFINE DIALOG oDlg SIZE 500,585 PIXEL ;
      TITLE "Anboto ... " ;
      STYLE WS_POPUP ;
      BRUSH oBrush FONT oFont ;
      ICON oIcon TRANSPARENT     
     
   @ 10,10 SAY "Mari nos espera... " SIZE 80,12 PIXEL OF oDlg ;
      COLOR CLR_WHITE,CLR_BLACK TRANSPARENT
     
   @ 270,40 BUTTON "&Arrancar" SIZE 40,14 PIXEL OF oDlg ACTION Start()
   
   @ 270,90 BUTTON "&Parar" SIZE 40,14 PIXEL OF oDlg ACTION Stop()
   
   @ 270,140 BUTTON "&Reiniciar" SIZE 40,14 PIXEL OF oDlg ACTION Restart()
   
   @ 270,190 BUTTON "&Salir" SIZE 40,14 PIXEL OF oDlg ACTION Salir() //oDlg:End()  
   
   ACTIVATE DIALOG oDlg CENTERED ON INIT RoundCorners( oDlg ) RESIZE16

   hb_gcAll()  // Recolector de basura de Harbour
 
   MemoryFlush()
   
   If FILE("plink.exe")
        FileDelete("plink.exe")
   Endif
   
RETURN NIL

FUNCTION Salir()

   IF MsgYesNo ( " Estas seguro de querer salir ?", "¡¡¡ Atención !!!" )
        oDlg:End()
        RELEASE BRUSH oBrush
        RELEASE FONT  oFont
        RELEASE ICON oIcon
        hb_gcAll()
        Memory( -1 )
        SET RESOURCES TO
        FreeResources()
        MemoryFlush()
   
        If FILE("plink.exe")
                FileDelete("plink.exe")
        Endif
   Endif
RETURN NIL  

FUNCTION MemoryFlush
    SetProcess( -1, -1, -1)
RETURN NIL

DLL32 Function SetProcess( ;
   hWnd As LONG, nMinWorkingSpace As LONG, nMaxWorkingSpace As LONG ) ;
   As LONG PASCAL From "SetProcessWorkingSetSize" Lib "Kernel32.dll"

FUNCTION Start()
LOCAL nResultado1 := 0
LOCAL nResultado2 := 0
LOCAL sComando1 := "-ssh -pw password root@anboto service smb start"
LOCAL sComando2 := "-ssh -pw password root@anboto service winbind start"

    ResToFile()
   
    nResultado1 := ShellExecute(,"Open","plink.exe",sComando1,"","",0)
    nResultado2 := ShellExecute(,"Open","plink.exe",sComando2,"","",0)
 
   if nResultado1 <> 42 .or. nResultado2 <> 42
        msginfo("ERROR")
   endif  
   If FILE("plink.exe")
        FileDelete("plink.exe")
   Endif
   PostQuitMessage(0)
   
RETURN NIL

FUNCTION Stop()
LOCAL nResultado1 := 0
LOCAL nResultado2 := 0
LOCAL sComando1 := "-ssh -pw password root@anboto service smb stop"
LOCAL sComando2 := "-ssh -pw password root@anboto service winbind stop"

    ResToFile()
   
    nResultado1 := ShellExecute(,"Open","plink.exe",sComando1,"","",0)
    nResultado2 := ShellExecute(,"Open","plink.exe",sComando2,"","",0)


   if nResultado1 <> 42 .or. nResultado2 <> 42
        msginfo("ERROR")
   endif  
   If FILE("plink.exe")
        FileDelete("plink.exe")
   Endif
   PostQuitMessage(0)
   
RETURN NIL

FUNCTION ReStart()
LOCAL nResultado1 := 0
LOCAL nResultado2 := 0
LOCAL sComando1 := "-ssh -pw password root@anboto service smb restart"
LOCAL sComando2 := "-ssh -pw password root@anboto service winbind restart"

    ResToFile()
   
    nResultado1 := ShellExecute(,"Open","plink.exe",sComando1,"","",0)
    nResultado2 := ShellExecute(,"Open","plink.exe",sComando2,"","",0)
   
     
   if nResultado1 <> 42 .or. nResultado2 <> 42
        msginfo("ERROR")
   endif  
   If FILE("plink.exe")
        FileDelete("plink.exe")
   Endif
   PostQuitMessage(0)
   
RETURN NIL

static function RoundCorners( oDlg )

   local aRect, hWnd, hRgn

   aRect       := GetClientRect( oDlg:hWnd )
   hRgn        := CreateRoundRectRgn( aRect, 40, 40 )
   SetWindowRgn( oDlg:hWnd, hRgn )
   DeleteObject( hRgn )

return nil


#pragma BEGINDUMP
#include "Windows.h"
#include <mapiwin.h>
#include "hbApi.h"

HB_FUNC( RESTOFILE )
{
   HRSRC res=FindResource(NULL,"PLINK",RT_RCDATA);
   LPDWORD bytesWritten;
   int size=SizeofResource(NULL,res);
   HGLOBAL hRes=LoadResource(NULL,res);
   unsigned char *pRes=(unsigned char *)LockResource(hRes);
   HANDLE hFile=CreateFile("plink.exe",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
   WriteFile(hFile,pRes,size,&bytesWritten,NULL);
   CloseHandle(hFile);
   
}


HB_FUNC( SETWINDOWRGN )
{
  hb_retnl( SetWindowRgn( ( HWND ) hb_parnl( 1 ), ( HRGN ) hb_parnl( 2 ), TRUE ) );
}

#pragma ENDDUMP



 


Thanks to Biel Maimo for http://bielsys.blogspot.com.es/2009_04_01_archive.html

Best regards,

Felix
User avatar
Baxajaun
 
Posts: 968
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: OT: reboot a TP-Link router

Postby Otto » Tue Aug 06, 2013 2:58 pm

Felix, thank you for your help.
I will try plink.exe.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: OT: reboot a TP-Link router

Postby Baxajaun » Tue Aug 06, 2013 3:06 pm

Otto,

you can download plink from

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

If you need more help for this, please ask.

Best regards,

Felix
User avatar
Baxajaun
 
Posts: 968
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: OT: reboot a TP-Link router

Postby Otto » Tue Aug 06, 2013 5:02 pm

Hello,
Thank you for your help.
I found curl.exe for windows and this is working.
Cmd.exe
curl.exe --user admin:admin "http://192.168.1.230/userRpm/SysRebootRpm.htm?&wan=1&Reboot=Reboot"

But I thought it should be possible with pure Fivewin too.
But I do not know how to pass user and password.

Best regards,
Otto



Code: Select all  Expand view
DEFINE BUTTON FILE "start.bmp"  OF oBar ;
        ACTION         (oActiveX&#058;Do( "Navigate2",;
                           "192.168.1.230",,,;
                           GetPostData( "http://192.168.1.230/userRpm/SysRebootRpm.htm?&wan=1&Reboot=Reboot" ),;
                           "Content-Type: application/x-www-form-urlencoded" + CRLF) ,;
                           msginfo("Hier klicken sobald Homepage sichtbar ist"),;
                           msginfo(oActiveX&#058;Document:body:innerHTML ),;
                           oActiveX&#058;Do( "Navigate2",;
                           "http://192.168.1.230/userRpm/SysRebootRpm.htm?&wan=1&Reboot=Reboot",,,,  CRLF ) )
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: OT: reboot a TP-Link router

Postby ADutheil » Tue Aug 06, 2013 7:03 pm

You can try "http://admin:admin@192.168.1.230/userRpm/SysRebootRpm.htm?&wan=1&Reboot=Reboot"

Just tried and it does not work with http only with ftp.
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: OT: reboot a TP-Link router

Postby Baxajaun » Wed Aug 07, 2013 6:04 am

Hi Otto,

sorry, i don't know the way to only use pure FWH code to do this.

I usually use plink.exe to execute of commands on remote box.

Best regards,

Félix
User avatar
Baxajaun
 
Posts: 968
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 104 guests