Windows Script-Explanation of local ARP static binding batch files [binding IP-Mac script details]

Source: Internet
Author: User

Http://www.x5dj.com/Blog/00534041/00389986.shtml

The original batch processing file is as follows:

@ Echo off
If exist ipconfig.txt del ipconfig.txt
Ipconfig/All> ipconfig.txt
If exist phyaddr.txt del phyaddr.txt
Find "physical address" ipconfig.txt> phyaddr.txt
For/F "Skip = 2 tokens = 12" % m in (phyaddr.txt) do set MAC = % m
If exist ipaddr.txt del ipaddr.txt
Find "ip address" ipconfig.txt> ipaddr.txt
For/F "Skip = 2 tokens = 15" % I in (ipaddr.txt) do set IP = % I
ARP-S % IP % Mac %

Del ipaddr.txt
Del ipconfig.txt
Del phyaddr.txt

Exit

My explanations starting //

@ Echo off
// Close the command echo

If exist ipconfig.txt del ipconfig.txt
// Delete the file ipconfig.txt if it exists.

Ipconfig/All> ipconfig.txt
// Write the display result of the ipconfig/all command to ipconfig.txt

If exist phyaddr.txt del phyaddr.txt
// Delete phyaddr.txt if it exists.

Find "physical address" ipconfig.txt> phyaddr.txt
// Search for the physical address field in the ipconfig.txt file and write the field content to phyaddr.txt

For/F "Skip = 2 tokens = 12" % m in (phyaddr.txt) do set MAC = % m
// In the phyaddr.txt file, jump from the first line to the next line, that is, start from the third line, and set the value to the Mac variable, for example, physical address .........: 00-e0-fc-0c-a8-4f. Each continuous value is a symbol.
Symbol 1: physical
Symbol 2: address.
Symbol 3 :.
Symbol 4 :.
Symbol 5 :.
Symbol 6 :.
Symbol 7 :.
Symbol 8 :.
Symbol 9 :.
Symbol 10 :.
Symbol 11 ::
Symbol-E0-FC-0C-A8-4F
Tokens = 12. Now you should understand it, but it is worth noting that the variables in the for command are represented by % x in batch processing, however, the input in the command prompt is expressed as % x. Remember

If exist ipaddr.txt del ipaddr.txt
Find "ip address" ipconfig.txt> ipaddr.txt
For/F "Skip = 2 tokens = 15" % I in (ipaddr.txt) do set IP = % I
ARP-S % IP % Mac %
// The above can be easily understood in comparison with my previous explanations

Del ipaddr.txt
Del ipconfig.txt
Del phyaddr.txt

Exit
// If you still cannot understand these sentences, it will be too much ''''''
The above script is bound to the local IP address and MAC address.
The following is the binding of the gateway IP address and MAC address.

@ Echo off
If % ~ N0 = ARP exit
If % ~ N0 = ARP exit
If % ~ N0 = ARP exit
ECHO is obtaining local information .....
: IP
For/F "Skip = 13 tokens = 15 usebackq" % I in ('ipconfig/all') do set IP = % I & goto Mac
: Mac
Echo IP: % IP %
For/F "Skip = 13 tokens = 12 usebackq" % I in ('ipconfig/all') do set MAC = % I & goto custom IP
: Elastic IP
Echo Mac: % Mac %
ARP-S % IP % Mac %
ECHO is obtaining gateway information .....
For/F "Skip = 17 tokens = 13 usebackq" % I in ('ipconfig/all') do set multicast IP = % I & goto encrypt Mac
: Running Mac
Echo IP: % gateip %
For/F "Skip = 3 tokens = 2 usebackq" % I in ('Arp-A % Taobao IP % ') do set hosts MAC = % I & goto start
: Start
Echo Mac: % running Mac %
ARP-d
ARP-S % gateip % gatemac %
Echo operation completed !!!
Exit

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.