2017-01-26 156 views
-4

該項目是一個帶有登錄屏幕的小型命令終端。但是,在我通過登錄後,它無法再打開。有沒有人有任何建議/修復? (另外,我認識到,部分代碼不是由我做100%)爲什麼登錄後不會運行此批處理腳本?

@echo off 
:LOGIN 
set/p uname= < HoodedBlack 
set/p pass=< Password 
title Login 
cls 
echo ------------------------------------------------- 
echo   HoodedBlack's Mainframe V0.1 
echo      Login 
echo ------------------------------------------------- 
echo. 
echo. 
set/p "unamel=    Username : 
set/p "passwordl=    Password : 
echo. 

IF "%passwordl%"=="Password" goto LOADING 

IF NOT "%passwordl%"=="Password" 
goto ERROR 


:ERROR 
echo ------------------------------------------------- 
echo      Error 
echo ------------------------------------------------- 
echo Invalid Username or password 
echo An Admin has been notified of this attempt. 
pause 




:LOADING 
title Loading... 
set load=%load%!!!!!!! 
cls 
echo ------------------------------------------------- 
echo      Login 
echo ------------------------------------------------- 
echo. 
echo. 
echo     Username : %unamel% 
echo     Password : %passwordl% 
echo. 
echo. 
echo   Logging in... 
echo   =================================== 
echo   %load% 
echo   =================================== 
echo.        Please Wait... 
echo. 
ping localhost -n 2 >nul 
set/a loadnum=%loadnum% +1 
if %loadnum%==5 goto DONE 
goto LOADING 

:DONE 
title Done 
cls 
echo ------------------------------------------------- 
echo      Done 
echo ------------------------------------------------- 
echo. 
echo    # 
echo    # 
echo  #  #   Login Successfully 
echo  # # 
echo  # 
echo. 
echo. 
echo ------------------------------------------------- 
pause 
goto WELCOME 

:WELCOME 
title Welcome 
cls 
echo ---------------------------------------------------- 
echo Welcome, HoodedBlack! Your rank is: Mainframe Owner 
echo    Mainframe v0.1 HoodedBlack 
echo ---------------------------------------------------- 
echo. 
echo Hello!   
echo Say "cmds" for a list of commands 
echo or say "exit" to exit the mainframe    
echo. 
echo. 
echo. 
echo. 
set INPUT= 
set /P INPUT=Type input: %=% 
If %INPUT%=="cmds" goto cmds 
If NOT %INPUT%=="cmds" 
then 
If %INPUT%=="exit" goto exit 
If NOT %INPUT%=="exit" 
then 
If %INPUT%=="DDoS" goto DDoS 
If %INPUT%=="DDoS" 
then 
If %INPUT%=="DoS" goto DoS 
If %INPUT%=="DoS" 
then 
If %INPUT%=="Password" goto pword 
If NOT %INPUT%=="Password" 
then pause 




:cmds 
title cmds 
cls 
echo ------------------------------------------------- 
echo      Commands list 
echo ------------------------------------------------- 
echo. 
echo    DDoS: Redirects you to a ddos service. 
echo    DoS: Sends a ping dos attack 
echo     (More commands coming soon!) 
echo ------------------------------------------------- 
pause 
goto WELCOME 

:exit 
title exit 
exit 


:DDoS 
start www.alphastress.com 

:DoS 
title cmds 
cls 
echo ------------------------------------------------- 
echo   Ping attack (Denial Of Service) 
echo ------------------------------------------------- 
echo Select an IP to send the attack to 
echo 
echo ------------------------------------------------- 


:pword 
title Password Generator 
cls 
echo I will make you a new password. 
echo Please write the password down somewhere in case you forget it. 
echo ----------------------------------------­----------------------- 
echo 1) 1 Random Password 
echo 2) 5 Random Passwords 
echo 3) 10 Random Passwords 
echo Input your choice 
set input= 
set /p input= Choice: 
if %input%==1 goto A if NOT goto Start2 
if %input%==2 goto B if NOT goto Start2 
if %input%==3 goto C if NOT goto Start2 
:A 
cls 
echo Your password is %random% 
echo Now choose what you want to do. 
echo 1) Go back to the beginning 
echo 2) Exit 
set input= 
set /p input= Choice: 
if %input%==1 goto Start2 if NOT goto Start 2 
if %input%==2 goto Exit if NOT goto Start 2 
:Exit 
exit 
:B 
cls 
echo Your 5 passwords are %random%, %random%, %random%, %random%, %random%. 
echo Now choose what you want to do. 
echo 1) Go back to the beginning 
echo 2) Exit 
set input= 
set /p input= Choice: 
if %input%==1 goto Start2 if NOT goto Start 2 
if %input%==2 goto Exit if NOT goto Start 2 
:C 
cls 
echo Your 10 Passwords are %random%, %random%, %random%, %random%, %random%, %random%, %random%, %random%, %random%, %random% 
echo Now choose what you want to do. 
echo 1) Go back to the beginning 
echo 2) Exit 
set input= 
set /p input= Choice: 
if %input%==1 goto Start2 if NOT goto Start 2 
if %input%==2 goto Exit if NOT goto Start 2 
+0

你在'uname1'和'password1''set/p'行缺少關閉引號,但是這是除了_actually_破壞你的代碼外。如果您要使用多行if語句來驗證「%password1%」等於「Password」,您需要使用圓括號。 – SomethingDark

+0

@HoodedBlack雖然在Windows批處理中學習和編寫腳本可能很有用,但您也可以嘗試使用PowerShell。使用起來更容易,具有很好的文檔並且非常強大。我建議你試試PowerShell,我相信你會愛上它的。順便說一句,PowerShell隨Windows一起提供,你不需要安裝任何東西來開始使用它。請參閱https://powershell.org/和https://msdn.microsoft.com/en-us/powershell/ – bahrep

回答

0

感謝 bahrep ...

HoodedBlack - >一些調整和一些新的命令來檢查:

@echo off 

setlocal 
:MAIN_LOOP 
call :LOGIN 
if "%AUTHENTICATED%" == "TRUE" (
    call :LOADING 
    call :WELCOME 
    ) 
goto MAIN_LOOP 
endlocal 

goto END 
REM **************************************************************************** 


:LOGIN 
set UNAME=HoodedBlack 
set PASS=Password 
set AUTHENTICATED=TRUE 
set UNAMEL= 
set PASSWORDL= 
title Login 
cls 
color 0a 
echo ------------------------------------------------- 
echo   HoodedBlack's Mainframe V0.1 
echo      Login 
echo ------------------------------------------------- 
echo. 
echo. 
set/p "UNAMEL=    Username : 
set/p "PASSWORDL=    Password : 
echo. 

REM *** /i makes comparison non-case sensitive. 
if /i "%UNAMEL%" NEQ "%UNAME%" set AUTHENTICATED=FALSE 
if "%PASSWORDL%" NEQ "%PASS%" set AUTHENTICATED=FALSE 
if "%AUTHENTICATED%" == "TRUE" (
    call :LOGIN_OK 
    goto END 
    ) 

color 4e 
title Access Denied 
echo ------------------------------------------------- 
echo      Error 
echo ------------------------------------------------- 
echo Invalid Username or password 
echo An Admin has been notified of this attempt. 
echo. 
echo Press any key. 
pause>nul 
goto END 
REM **************************************************************************** 


:LOADING 
title Loading... 
set /a LOADNUM=0 
set LOAD= 
:LOAD_LOOP 
set LOAD=%LOAD%!!!!!!! 
cls 
echo ------------------------------------------------- 
echo      Login 
echo ------------------------------------------------- 
echo. 
echo. 
echo     Username : %unamel% 
rem echo     Password : %passwordl% 
echo. 
echo. 
echo   Logging in... 
echo   =================================== 
echo   %LOAD% 
echo   =================================== 
echo.        Please Wait... 
echo. 
ping localhost -n 2 >nul 
set /a LOADNUM+=1 
if %LOADNUM% LSS 5 goto LOAD_LOOP 
goto END 
REM **************************************************************************** 


:LOGIN_OK 
title Done 
cls 
echo ------------------------------------------------- 
echo      Done 
echo ------------------------------------------------- 
echo. 
echo    # 
echo    # 
echo  #  #   Login Successfully 
echo  # # 
echo  # 
echo. 
echo. 
echo ------------------------------------------------- 
pause 
goto END 
REM **************************************************************************** 


:WELCOME 
title Welcome 
cls 
echo ---------------------------------------------------- 
echo Welcome, HoodedBlack! Your rank is: Mainframe Owner 
echo    Mainframe v0.1 HoodedBlack 
echo ---------------------------------------------------- 
echo. 
echo Hello!   
echo Say "cmds" for a list of commands 
echo or say "exit" to exit the mainframe    
echo. 
echo. 
:INPUT_LOOP 
set INPUT= 
set /P INPUT=Type input: 
if /i "%INPUT%" == "CMDS"  call :CMDS & goto INPUT_LOOP 
if /i "%INPUT%" == "DDOS"  call :DDoS & goto INPUT_LOOP 
if /i "%INPUT%" == "DOS"  call :DoS & goto INPUT_LOOP 
if /i "%INPUT%" == "PASSWORD" call :pword & goto INPUT_LOOP 
if /i "%INPUT%" == "EXIT"  goto END 
echo Unrecognised command. 
goto INPUT_LOOP 
REM **************************************************************************** 


:CMDS 
title cmds 
echo. 
echo ------------------------------------------------- 
echo      Commands list 
echo ------------------------------------------------- 
echo. 
echo    DDoS: Redirects you to a ddos service. 
echo    DoS: Sends a ping dos attack 
echo     (More commands coming soon!) 
echo ------------------------------------------------- 
echo. 
goto END 
REM **************************************************************************** 


:DDoS 
start www.alphastress.com 
goto END 
REM **************************************************************************** 


:DoS 
title cmds 
cls 
echo ------------------------------------------------- 
echo   Ping attack (Denial Of Service) 
echo ------------------------------------------------- 
echo Select an IP to send the attack to 
echo. 
echo ------------------------------------------------- 
pause 
goto END 
REM **************************************************************************** 


:PWORD 
title Password Generator 
cls 
echo I will make you a new password. 
echo Please write the password down somewhere in case you forget it. 
echo ----------------------------------------­----------------------- 
echo 1) 1 Random Password 
echo 2) 5 Random Passwords 
echo 3) 10 Random Passwords 
echo Input your choice 
set INPUT= 
set /p INPUT= Choice: 

if "%INPUT%" == "1" (
    echo Your password is %RANDOM%. 
    goto PASSWORD_DONE 
    ) 
if "%INPUT%" == "2" ( 
    echo Your 5 passwords are %RANDOM%, %RANDOM%, %RANDOM%, %RANDOM%, %RANDOM%. 
    goto PASSWORD_DONE 
    ) 
if "%INPUT%" == "3" ( 
    echo Your 10 Passwords are %RANDOM%, %RANDOM%, %RANDOM%, %RANDOM%, %RANDOM%, %RANDOM%, %RANDOM%, %RANDOM%, %RANDOM%, %RANDOM%. 
    goto PASSWORD_DONE 
    ) 
echo Invalid option - press any key. 
pause >nul 
goto PWORD 

:PASSWORD_DONE 
echo. 
goto END 
REM **************************************************************************** 


:END 
REM **************************************************************************** 

我同意上面的PowerShell參考。 Windows的shell腳本有點挑剔,主要是因爲更先進的東西被「卡住」,而不是「設計」。其中一個例子是子例程 - 是的,您可以執行這些操作(請參閱調用:SUBROUTINE_NAME以上),但它們不支持返回聲明。相反,您必須強制腳本到達文件末尾,此時命令解釋程序意識到它的「堆棧」中有一個返回行號。這就是爲什麼你會在上面看到轉到END(標籤:END可能是任何名稱)。

祝你好運!