FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour OT: reboot a TP-Link router
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
OT: reboot a TP-Link router
Posted: Mon Aug 05, 2013 08: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"
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: OT: reboot a TP-Link router
Posted: Tue Aug 06, 2013 02: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 (fw): Select all Collapse
#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
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: OT: reboot a TP-Link router
Posted: Tue Aug 06, 2013 02:58 PM

Felix, thank you for your help.
I will try plink.exe.
Best regards,
Otto

Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: OT: reboot a TP-Link router
Posted: Tue Aug 06, 2013 03: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
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: OT: reboot a TP-Link router
Posted: Tue Aug 06, 2013 05: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 (fw): Select all Collapse
DEFINE BUTTON FILE "start.bmp"  OF oBar ;
        ACTION         (oActiveX: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:Document:body:innerHTML ),;
                           oActiveX:Do( "Navigate2",;
                           "http://192.168.1.230/userRpm/SysRebootRpm.htm?&wan=1&Reboot=Reboot",,,,  CRLF ) )
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: OT: reboot a TP-Link router
Posted: Tue Aug 06, 2013 07: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
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: OT: reboot a TP-Link router
Posted: Wed Aug 07, 2013 06: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

Continue the discussion