SUNTB write IP address settings to switch batch processing _dos/bat

Source: Internet
Author: User
Tags dns2 goto
Fixed a bug that extracted the name of the network connection because the space used as the separator in the for
If the network connection name is "Local Area Connection 2", it will only be recognized as "Local Area Connection", causing the setting to fail
has now been corrected

Note: 1, you can choose to set the network connection
2, can manually set fixed IP, can also be automatically obtained by DHCP
3, you can preset in batch processing mac and IP corresponding data, when the intranet has a Mac binding can quickly query the corresponding IP
4, DNS settings to provide four types of data (China Telecom, Unicom/China Netcom, China Mobile/national railcom, intranet Gateway)
DNS for Fuzhou area data, please change to local broadband operator DNS
5, add a function: After setting up, you can choose whether the local Mac and IP data added to this batch processing so that the next automatic recognition

The batch code is as follows:
Copy Code code as follows:

@title IP address settings Toggle batch by SUNTB

@echo Off & setlocal enabledelayedexpansion

If exist "%windir%\system32\slmgr.vbs" (
Echo.&echo This batch is required to run as an administrator in VISTA and WIN7
Echo.&echo See if the title bar information for the batch window starts with "admin:"
Echo.&echo if the above conditions are met, you can press any key to continue, otherwise please quit the batch and re-run 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!=%%a)
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!=%%a )

: Net
Echo.&echo Please select the current network link for this confidential setting:
FOR/L%%a in (1,1,!n!) do (
Echo.
Echo%%a-!net%%a! -!netcard%%a!
echo MAC Address:! mac%%a!
)
Echo.&set num=&set/p num= Please enter the serial number and return to select:
Cls
If defined net%num% (set Net=!net%num%!&set mac=! mac%num%: =!&set mac=! mac:~0,17!) Else (Echo.&echo entered the serial number incorrectly, please choose again!) &goto:net)

: Lib
Set mask=255.255.255.0
Set gate=192.168.0.1
Cls&echo.&echo Current!net! The MAC for! Mac!
For/f "tokens=2 delims=[]"%%a in (' findstr/i '!) mac! '%0 ') do set ip=%%a
If defined IP (
Set Inbat=1
Echo.&echo the corresponding data in the batch processing database
Echo.&echo IP:! Ip!
Echo.&echo Subnet Mask:! mask!
Echo.&echo Gateway:! gate!
echo.&set/p ip= If you want to change the IP data, please enter and return manually, such as the default value, please return directly:
echo.&set/p mask= If you want to change the subnet mask data, please enter and return manually, if the default value, please return directly:
echo.&set/p gate= If you need to change the gateway data, please enter and return manually, if the default value, please return directly:
Goto:isp
) Else (
Set inbat=0
Echo.&echo the corresponding IP is not found in the batch database, please select IP settings manually
Goto:lan
)

: LAN
Echo.&echo the current network link to be set is:
Echo.&echo!net! -!netcard%num%!
Echo.&echo Please select the IP setting method:
Echo.&echo 1-Manually set fixed IP
Echo.&echo 2-DHCP Automatic Acquisition
Echo.&set choose=&set/p choose= Please enter the serial number and return to select:
Cls
If%choose% equ 1 goto:set
If%choose% equ 2 goto:d HCP
Echo.&echo entered the serial number incorrectly, please choose again! &goto:lan

: Set
Set ip=192.168.0.9
Cls&echo.&echo default IP is! Ip! , if you want to change please manually enter and return, such as the default value, please return directly:
echo.&set/p ip=
Cls&echo.&echo The default subnet mask is! mask! , if you want to change please manually enter and return, such as the default value, please return directly:
echo.&set/p mask=
Cls&echo.&echo Default gateway is! gate! , if you want to change please manually enter and return, such as the default value, please return directly:
echo.&set/p gate=
: ISP
Cls&echo.&echo Please select the broadband line corresponding to DNS (Fuzhou area):
Echo.&echo 1-China Telecom
Echo.&echo 2-China Unicom/China Netcom
Echo.&echo 3-Chinese mobile/China railcom
Echo.&echo 4-Intranet Gateway%gate%
Echo.&set isp=&set/p isp= Please enter the serial number and return to select:
If%isp% equ 1 (call:10000&goto:d oset)
If%isp% equ 2 (call:10010&goto:d oset)
If%isp% equ 3 (call:10086&goto:d oset)
If%isp% equ 4 (set Dns1=%gate%&goto:d oset)
Echo.&echo entered the serial number incorrectly, please choose again! &goto:isp
:d Oset
Please wait while the Cls&echo.&echo is set%net% IP address is%ip% ...
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

:d HCP
Please wait while Cls&echo.&echo is setting up%net% for automatic access to IP and DNS ...
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 settings are complete, the current IP information as above, please carefully review
If!inbat! Equ 0 (
Echo.&echo Enter Y and enter to add native MAC and IP data to this batch so that it can be automatically identified next time
echo.&set/p addbat= If you do not add data, please return directly to exit:
if/i!addbat! Equ Y echo>>%0 [! mac!]! Ip!
) Else (Pause>nul)
Exit

************************************************************
:: The following DNS is only for use in Fuzhou area, please change to the local broadband operators DNS

: 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
************************************************************
Host Mac and IP allocation corresponding database, when the intranet has a Mac binding can quickly query the corresponding IP
Can be added in sample format ([MAC address]ip address), separate row for each set of data
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.