Batch binding IP Script interpretation

Source: Internet
Author: User
Tags echo display goto

Foreword source File command explain REM hide Batch run window echo parameter if exist Bbat del bbat netsh i i show inaaatxt popup box for parameter delims tokens netsh summary

Preface


Because everyone recently in dealing with this file, have to say in fact suddenly get this when still feel pretty distressed, and I as a member, a lot of things can not explain, do not know the principle, just know to use, actually feel still quite uncomfortable, so took some time to study a bit, although said no research is very thorough , but most of the source files that can be explained

REM Batch hidden Run effect
@echo OFF
If "%1" = = "h" goto begin 
Start Mshta vbscript:createobject ("Wscript.Shell"). Run ("" "%~nx0" "H", 0) (window.close) &&exit 
: Begin

if exist B.bat del b.bat
if exist aaa.txt del Aaa.txt

REM Query network card information, saved in Aaa.txt
netsh i i show in>aaa.txt

rem pop-up prompt box, tell everyone has been bound successfully
@echo MsgBox "Good jod~ Ip-mac has been successfully bound. ">msg.vbs 
@msg. vbs
@del msg.vbs

rem loops through the 4th line of Aaa.txt to find the contents of the 1th column, stored in the variable i.
for/f "Skip=3 Tokens=1"%%i in (Aaa.txt) does ( 

REM writes the content behind Echo (bound Gateway) to B.bat.
echo netsh-c "I i" add neighbors%%i "192.168.24.254" "58-6a-b1-f4-a1-f0" >b.bat

REM starts looping through the 4th line of Aaa.txt to find the contents of the 1th, 2 columns (i.e., IP and Mac), which are stored in variables a and B.
for/f "skip=2 tokens=1-2 delims=   "%%a in (Ip-macv7.0.txt) does (

REM writes the contents behind Echo (Binding all Ip&mac) to B.bat.
echo netsh-c "I i" add neighbors%%i "%%a" "%%b" >>b.bat
)
rem Execute binding command
B.bat
)


if exist B.bat del b.bat
if exist aaa.txt Del Aaa.txt
Command Explanation REM


is equivalent to the VB program ' is the meaning of annotations, in the program does not work to hide the batch run window


The following code is the use of batch processing command to implement the hidden batch Run window, the disadvantage: you will see a window flashed over, advantages: simple, directly add can
Another way to hide the batch processing window of the method we can Baidu, here more, do not write

@echo OFF
If "%1" = = "h" goto begin 
Start Mshta vbscript:createobject ("Wscript.Shell"). Run ("" ""%~nx0 "" H ", 0) ( Window.close) &&exit 
: Begin


* After the batch runs, the command window disappears, and it hides itself as a process svchost.ext running in the background

Explain that Svchost.ext is a system program that belongs to the Microsoft Windows operating system, and Microsoft's official explanation is Svchost.txt is the generic host process name of the service running from the dynamic link library (DLL), this program is very important to the normal operation of the system, and can not be ended, I think the most important here is not to be closed, (we are interested in Baidu, here do not explain too much) @, echo, Parameters


The *@ character is placed before the command to turn off Echo, regardless of whether ECHO is open at this point, that is, the command effect behind @ is hidden
*echo display a message, or turn the command back on or off
*%1-%9 is the meaning of the parameter if exist B.bat del B.bat

If exist B.bat del b.bat
if exist aaa.txt del Aaa.txt


If you have b.bat this file, delete B.bat
If you have aaa.txt this file, delete aaa.txt
Del Delete at least one file netsh i i show in>aaa.txt

Netsh i i show in>aaa.txt

Here is a query to find the IDX number you used to connect to the Internet in the above display.


IDX is the local active NIC number, I'm here 11 is the IDX number
In transmission units of network media, the MTU is the maximum number of bytes of a packet. MTU, the Maximum transmission unit (Maximum transmission UNIT,MTU) is the maximum datagram size (in bytes) that can be passed on a layer of a communication protocol. (You can own Baidu) pop-up prompt box

The REM popup box tells you that you have successfully bound
@echo MsgBox "Good jod~ Ip-mac has been bound successfully. ">msg.vbs 
@msg. vbs
@del Msg.vbs


This is the meaning of the pop-up cue box

VBS is a Visual Basic-based scripting language. The full name of VBS is: Microsoft Visual Basic Script editon.
VBS is written in TXT and then saved directly to the VBS format. Feel still quite fun, we are interested can Baidu check, there are many spoof code is implemented with VBS

">" means that the original output to the screen of data written to other devices, files,
Which is now "MsgBox" "Hello" is written in a VBS file named MSG
Then run Msg.vbs, attentive people can find that when you do not click on that certain time folder will appear such a file

This file is the VBS file that runs, and when we click OK, the file is gone, because the next code deletes it.

Del Msg.vbs


But I think that can be used without VBS files, can be directly implemented using batch method, the effect is the same, as shown in figure

Msg%username% "Hello." "

For parameter


For: Runs a specified command for each file in a set of files

Because there are many parameters for the for, there is no explanation here, just explain the/F parameters used in the text

Format:

for/f ["Options"]%%i in (file) do command
for/f ["Options"]%%i in ("string") do command
for/f ["Options"]%%i in (' Command ') do command


This is probably the most common and strongest command to handle the output of files and some commands. delims

for/f "delims= symbol set"  %%i In (COMMAND1) do Command2


To summarize: Omit the delimiter and slice the string.
First, punctuation in the specified source is used as a delimiter. This allows the text to be divided into a number of small parts for easy reading and editing using batch commands.
Second, read the contents before the first delimiter. Ignores the contents after the first delimiter and delimiter, such as the need to read and edit, using commands such as tokens. Tokens

A word Summary: Extract columns.

for/f "Tokens=x,y,m-n"  %%i in  (Command1) do Command2


Extracts the specified column.
Notice the relation and difference between the column and the sentence.
Text content consists of a number of literal strings, which are separated by punctuation marks, and the statements between two punctuation marks are called "sentences".
When punctuation is specified as a delimiter by "tokens=", the text is divided into multiple parts. Each part of the corresponding line we call "column".
A column may be a sentence, or it may contain multiple sentences, depending on the punctuation mark defined by Delims. Netsh


The Netsh (network Shell) is a powerful network configuration command-line tool provided by the Windows system itself. Export configuration script: Netsh-c interface IP dump > C:\interface.txt import configuration script: Netsh-f c:\interface.txt.

Dump: Display a configuration script
Add: Adds a configuration item to the list of items.

netsh-c int IP dump > c:\ip.txt

This command displays the interface IP configuration for the current "local Area Connection" and is saved in the Ip.txt text file
After removing the original IP and Mac, we run the batch process so that the computer has a new IP address
Then run the following code to import the IP
Netsh-f C:\ip.txt

The command is to import the new IP configuration

After the run should be like this, if not it's okay, just put the original IP inside the empty can

Summary


I summed up some basic knowledge, if you have a patient look at the words, or relatively easy to understand, but if you want to see, you can again Baidu, after all, I wrote on the Baidu after I read the summary, or Baidu is more powerful, the other people can be the batch of things inside the open to look at, A closer look at the comments and code should still be understandable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.