[Script] Router Reboot Tool

Discussion in 'Scripting' started by Dark Dinosaur, Feb 11, 2022.

  1. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,761
    5,228
    120
    #1 Dark Dinosaur, Feb 11, 2022
    Last edited: Feb 11, 2022
    To refresh your IP via Command Line
    Using Ipconfig, dism, Telnet internal Tools &
    VB script to finish the job.

    In most cases User/Pass is:
    User Name :: [admin] or [Admin]
    Password :: [admin] or [Admin] or [1 -> 5]

    how to get command line to reboot your router ?
    manually enter telnet, use HELP command &
    find the command to reboot router.
    Tp-Link Archer VR 600 v2.0, command is :: dev reboot

    How to Create Shortcut ?
    Start, Run :: "C:\ProgramData\Microsoft\Windows\Start Menu\Programs"
    Make New shortcut. call it "Router reboot tool", Change Icon, Change to "Run as Administrator".
    Now enter start menu again, look for "Router Reboot tool", Left Click, Pin to Start

    Script Without Parameters, All hard Coded
    replace this values with your values.
    USER_NAME_HERE
    PASSOWRD_HERE
    Code:
    @cls
    @echo off
    setlocal enabledelayedexpansion
    
    :::: Run as administrator, AveYo: ps\vbs version
    1>nul 2>nul fltmc || (
        set "_=call "%~dpfx0" %*" & powershell -nop -c start cmd -args '/d/x/r',$env:_ -verb runas || (
        >"%temp%\Elevate.vbs" echo CreateObject^("Shell.Application"^).ShellExecute "%~dpfx0", "%*" , "", "runas", 1
        >nul "%temp%\Elevate.vbs" & del /q "%temp%\Elevate.vbs" )
        exit)
    
    for /f "tokens=2 delims=:" %%# in ('ipconfig /all ^| find /i "Default Gateway"') do (
        set ip_value=
        (echo '%%#' | >nul find /i "' '") || set "ip_value=%%#"
        if defined ip_value (
            set "ip_value=!ip_value: =!"
            goto :_next
        )
    )
    
    if not defined ip_value (
        echo:
        echo ERR :: Not found ip value
        echo:
        pause
        exit /b
    )
    
    :_next
    echo:
    echo Found ip Value :: !ip_value!
    echo:
    
    >nul 2>nul where telnet || (
        >nul 2>nul dism /online /Enable-Feature /FeatureName:TelnetClient
        >nul 2>nul where telnet || (
            echo:
            echo ERR :: Telnet not found
            echo:
            pause
            exit /b
        )
    )
    
    call :Create_Script PASSOWRD_HERE
    call :Add_Command dev reboot
    call :End_Script
    
    start "" /min "cmd" /c cscript "%temp%\tmp.vbs"
    telnet -l USER_NAME_HERE !ip_value!
    
    echo:
    echo:
    echo:
    echo Done ..
    echo:
    pause
    exit /b
    
    :Create_Script
     > "%temp%\tmp.vbs" echo set WshShell ^= WScript.CreateObject^("WScript.Shell"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 2000
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys"%*"
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    goto :eof
    
    :End_Script
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys"exit"
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys"exit"
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys"exit"
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    REM >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("^(c)")
    REM >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    goto :eof
    
    :Add_Command
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys"%*"
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 500
    goto :eof
    
    Script With Parameters, User Name, Password
    example "Router reboot tool" Admin 12566
    Code:
    @cls
    @echo off
    setlocal enabledelayedexpansion
    
    set "user=%1"
    set "Password=%2"
    
    :::: Run as administrator, AveYo: ps\vbs version
    1>nul 2>nul fltmc || (
        set "_=call "%~dpfx0" %*" & powershell -nop -c start cmd -args '/d/x/r',$env:_ -verb runas || (
        >"%temp%\Elevate.vbs" echo CreateObject^("Shell.Application"^).ShellExecute "%~dpfx0", "%*" , "", "runas", 1
        >nul "%temp%\Elevate.vbs" & del /q "%temp%\Elevate.vbs" )
        exit)
    
    for /f "tokens=2 delims=:" %%# in ('ipconfig /all ^| find /i "Default Gateway"') do (
        set ip_value=
        (echo '%%#' | >nul find /i "' '") || set "ip_value=%%#"
        if defined ip_value (
            set "ip_value=!ip_value: =!"
            goto :_next
        )
    )
    
    if not defined ip_value (
        echo:
        echo ERR :: Not found ip value
        echo:
        pause
        exit /b
    )
    
    :_next
    echo:
    echo Found ip Value :: !ip_value!
    echo:
    
    >nul 2>nul where telnet || (
        >nul 2>nul dism /online /Enable-Feature /FeatureName:TelnetClient
        >nul 2>nul where telnet || (
            echo:
            echo ERR :: Telnet not found
            echo:
            pause
            exit /b
        )
    )
    
    call :Create_Script %Password%
    call :Add_Command dev reboot
    call :End_Script
    
    start "" /min "cmd" /c cscript "%temp%\tmp.vbs"
    telnet -l %user% !ip_value!
    
    echo:
    echo:
    echo:
    echo Done ..
    echo:
    pause
    exit /b
    
    :Create_Script
     > "%temp%\tmp.vbs" echo set WshShell ^= WScript.CreateObject^("WScript.Shell"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 2000
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys"%*"
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    goto :eof
    
    :End_Script
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys"exit"
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys"exit"
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys"exit"
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    REM >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("^(c)")
    REM >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 1000
    goto :eof
    
    :Add_Command
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys"%*"
    >> "%temp%\tmp.vbs" echo WshShell.SendKeys^("{Enter}"^)
    >> "%temp%\tmp.vbs" echo WScript.Sleep 500
    goto :eof
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,761
    5,228
    120
    #2 Dark Dinosaur, Jun 2, 2022
    Last edited: Jun 2, 2022
    (OP)
    I did update it lately.
    now finding the INTERFACE its more easy

    Replace this.
    Code:
    for /f "tokens=2 delims=:" %%# in ('ipconfig /all ^| find /i "Default Gateway"') do (
        set ip_value=
        (echo '%%#' | >nul find /i "' '") || set "ip_value=%%#"
        if defined ip_value (
            set "ip_value=!ip_value: =!"
            goto :_next
        )
    )
    
    With This.
    Code:
    set ip_value=
    >nul 2>nul del /q "%temp%\ip.tmp"
    set "ps_cmd=Get-NetAdapter -physical| where status -eq 'up' | Get-NetIPConfiguration | Foreach {if ($_.IPv4DefaultGateway) {write-Host $_.IPv4DefaultGateway.NextHop}}"
    >"%temp%\ip.tmp" 2>&1 powershell.exe -noprofile -executionpolicy bypass -command "%ps_cmd%" && (
        if exist "%temp%\ip.tmp" set /p ip_value=<"%temp%\ip.tmp"
    )
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,761
    5,228
    120
    #3 Dark Dinosaur, Jun 27, 2022
    Last edited: Jun 27, 2022
    (OP)
    updated script. [v2.0]
    Code:
    @cls
    @echo off
    >nul chcp 437
    setlocal enabledelayedexpansion
    
    set "<=echo:&(echo|set /p =""
    set ">=")"
    
    set "_ip="
    set "_user=%1"
    set "_Password=%2"
    set "_vbsf="%temp%\.vbs""
    
    rem Run as administrator, AveYo: ps\VBS version
    >nul "fltmc" || ( set "_=call "%~dpfx0" %*"
        powershell -nop -c start 'cmd' -args '/d/x/r',$env:_ -verb runas || (
        "mshta" vbscript:execute^("createobject(""shell.application"").shellexecute(""cmd"",""/d/x/r "" &createobject(""WScript.Shell"").Environment(""PROCESS"")(""_""),,""runas"",1)(window.close)"^))|| (
        cls & echo:& echo Script elavation failed& pause)
        exit )
        
    set "ps_cmd=Get-NetAdapter -physical| where status -eq 'up' | Get-NetIPConfiguration | Foreach {if ($_.IPv4DefaultGateway) {write-Host $_.IPv4DefaultGateway.NextHop}}"
    for /f "usebackq delims=" %%# in (`powershell -nop -c "!ps_cmd!"`) do set "_ip=%%#"
    
    if not defined _ip (
        echo:
        echo ERROR :: fail to get IPv4DefaultGateway value
        echo:
        pause
        exit /b
    )
    
    >nul 2>nul where telnet || (
        >nul 2>nul dism /online /Enable-Feature /FeatureName:TelnetClient
        >nul 2>nul where telnet || (
            echo:
            echo ERROR :: Telnet not found
            echo:
            pause
            exit /b
        )
    )
    
     > !_vbsf! echo:
    >> !_vbsf! call :START_Script !_Password!
    >> !_vbsf! call :Add_Command dev reboot
    >> !_vbsf! call :End_Script
    
    start "" /min "cmd" /c cscript !_vbsf!
    telnet -l !_user! !_ip!
    
    echo:
    echo:
    echo:
    echo Done ..
    echo:
    pause
    del /q !_vbsf!
    exit /b
    
    :START_Script
    %<%set WshShell = WScript.CreateObject("WScript.Shell")%>%
    %<%WScript.Sleep 2000%>%
    %<%WshShell.SendKeys"%*"%>%
    %<%WshShell.SendKeys("{Enter}")%>%
    %<%WScript.Sleep 1000%>%
    goto :eof
    
    :End_Script
    %<%WshShell.SendKeys"exit"%>%
    %<%WshShell.SendKeys("{Enter}")%>%
    %<%WScript.Sleep 1000%>%
    %<%WshShell.SendKeys"exit"%>%
    %<%WshShell.SendKeys("{Enter}")%>%
    %<%WScript.Sleep 1000%>%
    %<%WshShell.SendKeys"exit"%>%
    %<%WshShell.SendKeys("{Enter}")%>%
    %<%WScript.Sleep 1000%>%
    REM %<%WshShell.SendKeys("(c)")%>%
    REM %<%WScript.Sleep 1000%>%
    %<%WshShell.SendKeys("{Enter}")%>%
    %<%WScript.Sleep 1000%>%
    goto :eof
    
    :Add_Command
    %<%WshShell.SendKeys"%*"%>%
    %<%WshShell.SendKeys("{Enter}")%>%
    %<%WScript.Sleep 500%>%
    goto :eof
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. case-sensitive

    case-sensitive MDL Expert

    Nov 7, 2013
    1,681
    731
    60
    I just unplug mine at night and when i plug it back in in the morning i have a different IP adress .
     
  5. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,761
    5,228
    120
    I'm lazy don't want to get to the router ...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...