SunTB write IP Address Settings switch Batch Processing

Source: Internet
Author: User
Tags dns2

Corrected an error in extracting the network connection name because a space was used as the Separator in.
If the network connection name is "local connection 2", it will only be recognized as "Local Connection", leading to a failure in setting
Corrected

Note: 1. You can select the network connection to be set.
2. You can manually set a fixed IP address or automatically obtain it through DHCP.
3. Multiple groups of MAC and IP data can be preset in batch processing. When MAC is bound to the Intranet, the corresponding IP address can be quickly queried.
4. DNS settings provide four types of data (China Telecom, China Unicom/China Netcom, China Mobile/China tietong, and Intranet gateway)
DNS is the data of Fuzhou region. Please change it to the DNS of each local broadband carrier.
5. Add another feature: After the configuration is complete, you can choose whether to add the MAC and IP data of the Local Machine to this batch for automatic identification next time.

The batch processing code is as follows:Copy codeThe Code is as follows: @ title IP Address Setting switching batch processing By SunTB

@ Echo off & setlocal enabledelayedexpansion

If exist "% windir % \ system32 \ slmgr. vbs "(
Echo. & echo this batch of processing must be run as an administrator in VISTA and WIN7.
Echo. & echo: Check whether the title bar information of the batch processing window starts with "Administrator :"
If echo. & echo meets the preceding conditions, press any key to continue. Otherwise, exit the batch processing and run it again as an administrator.
Pause> nul
)

Set n = 0
For/f "delims =:" % a in ('ipconfig/all ^ | findstr/I/B/c: "Ethernet adapter "') do (set/a n =! N! + 1 & set str = % a & set net! N! =! Str :~ 17 !)
Set n = 0
For/f "tokens = 2 delims =:" % a in ('ipconfig/all ^ | findstr/I/c: "Description "') do (set/a n =! N! + 1 & set netcard! N! = %)
Set n = 0
For/f "tokens = 2 delims =:" % a in ('ipconfig/all ^ | findstr/I/c: "Physical Address "') do (set/a n =! N! + 1 & set MAC! N! = %)

: Net
For echo. & echo, select the network link to be set for the current host:
For/l % a in (1, 1 ,! N !) Do (
Echo.
Echo % -! Net %! -! Netcard %!
Echo MAC address :! MAC %!
)
Echo. & set num = & set/p num = enter the serial number and press enter to select:
Cls
If defined net % num % (set NET =! Net % num %! & Set MAC =! MAC % num %: =! & Set MAC =! MAC :~ 0, 17 !) The number entered by else (echo. & echo is incorrect. Please reselect it! & Goto: net)

: Lib
Set MASK = 255.255.255.0
Set GATE = 192.168.0.1
Cls & echo. & echo current! NET! MAC! MAC!
For/f "tokens = 2 delims = []" % a in ('findstr/I "! MAC! "% 0') do set IP = %
If defined IP (
Set inbat = 1
Echo. & echo find the corresponding data in the batch processing database
Echo. & echo IP :! IP address!
Echo. & echo subnet mask :! MASK!
Echo. & echo Gateway :! GATE!
Echo. & set/p IP = If you need to change the IP data, manually enter and press Enter. If you want to take the default value, press enter directly:
Echo. & set/p MASK = If you need to change the subnet MASK data, manually enter and press Enter. If you want to take the default value, press enter directly:
Echo. & set/p GATE = If you need to change the gateway data, manually enter and press Enter. If you want to take the default value, press enter directly:
Goto: isp
) Else (
Set inbat = 0
Echo. & echo does not find the corresponding IP address in the batch processing database. Please manually select the IP Address Setting Method
Goto: lan
)

: Lan
Echo. & echo:
Echo. & echo! NET! -! Netcard % num %!
Select the IP Address Setting Method for echo. & echo:
Echo. & echo 1-manually set a fixed IP Address
Echo. & echo 2-automatically obtain DHCP
Echo. & set choose = & set/p choose = enter the serial number and press enter to select:
Cls
If % choose % equ 1 goto: set
If % choose % equ 2 goto: dhcp
Incorrect echo. & echo input sequence number. Please reselect it! & Goto: lan

: Set
Set IP = 192.168.0.9
The default IP address of cls & echo. & echo is! IP address! If you want to change the value, manually enter and press Enter. If you want to take the default value, press enter directly:
Echo. & set/p IP =
The default subnet mask of cls & echo. & echo is! MASK! If you want to change the value, manually enter and press Enter. If you want to take the default value, press enter directly:
Echo. & set/p MASK =
Cls & echo. & echo: the default gateway is! GATE! If you want to change the value, manually enter and press Enter. If you want to take the default value, press enter directly:
Echo. & set/p GATE =
: Isp
For cls & echo. & echo, select the DNS corresponding to the broadband line (Fuzhou ):
Echo. & echo 1-China Telecom
Echo. & echo 2-China Unicom/China Netcom
Echo. & echo 3-China Mobile/China tietong
Echo. & echo 4-Intranet gateway % GATE %
Echo. & set isp = & set/p isp = enter the serial number and press enter to select:
If % isp % equ 1 (call: 10000 & goto: doset)
If % isp % equ 2 (call: 10010 & goto: doset)
If % isp % equ 3 (call: 10086 & goto: doset)
If % isp % equ 4 (set DNS1 = % GATE % & goto: doset)
Incorrect echo. & echo input sequence number. Please reselect it! & Goto: isp
: Doset
Cls & echo. & echo is setting % NET %, IP address is % IP %, please wait...
Netsh interface ip set address name = "% NET %" static % IP % MASK % GATE % 1> nul
Netsh interface ip set dns name = "% NET %" static % DNS1 %> nul
If defined DNS2 netsh interface ip add dns name = "% NET %" % DNS2 % 2> nul
Goto: end

: Dhcp
Cls & echo. & echo is setting % NET % to automatically obtain the IP address and DNS. Please wait...
Netsh interface ip set address name = "% NET %" DHCP> nul 2> nul
Netsh interface ip set dns name = "% NET %" DHCP> nul 2> nul
Goto: end

: End
Cls
Ipconfig/all
Echo. & echo: The current IP address is set as above. Please check carefully
If! Inbat! Equ 0 (
Echo. & echo input Y and press enter to add MAC and IP data of the Local Machine to this batch for automatic identification next time
Echo. & set/p addbat = if no data is added, press enter to exit:
If/I! Addbat! Equ Y echo >>% 0 [! MAC!]! IP address!
) Else (pause> nul)
Exit

**************************************** ********************
: The following DNS is only available in Fuzhou. Please change it to the DNS of each broadband carrier in this region.

10000
Set DNS1 = 218.85.152.99
Set DNS2 = 218.85.157.99
Goto: eof

10010
Set DNS1 = 58.22.96.66
Set DNS2 = 218.104.128.106
Goto: eof

10086
Set DNS1 = 222.47.29.93
Set DNS2 = 222.47.62.142
Goto: eof
**************************************** ********************
The host MAC and IP address are allocated to the corresponding database. When MAC is bound to the Intranet, you can quickly query the corresponding IP address.
You can add an IP address in the example format ([MAC address]). Each group of data is a single row.
Example:
[11-22-33-44-55-66] 192.168.0.1
**************************************** ********************

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.