Code that batches get the name of the network card (with modification of IP, gateway, DNS script) _dos/bat

Source: Internet
Author: User
Copy Code code as follows:

:: Get the NIC name with the Ipconfig/all command.
for/f "tokens=2*"%%i in (' ipconfig/all^|find/i "Ethernet adapter" ') do set name=%%j
:: Remove the colon after the network card name with the for command.
for/f "tokens=1* delims=:"%%i in ("%name%") do set network card name =%%i

Apply the above script to modify DNS, such as the national DNS server crashed yesterday, the DNS changed to 202.96.199.132 can return to normal Internet.

modifying DNS Fragments
Copy Code code as follows:

for/f "tokens=2*"%%i in (' ipconfig/all^|find/i "Ethernet adapter" ') do set name=%%j
for/f "tokens=1* delims=:"%%i in ("%name%") do set network card name =%%i
Netsh-c interface IP Add DNS name= "% network card name%" addr=202.96.199.132 index=1
Netsh-c interface IP Add DNS name= "% network card name%" addr=202.96.64.38 index=2

Modify IP, subnet mask, gateway, DNS code
Copy Code code as follows:

for/f "tokens=2*"%%i in (' ipconfig/all^|find/i "Ethernet adapter" ') do set name=%%j
for/f "tokens=1* delims=:"%%i in ("%name%") do set network card name =%%i
Netsh-c interface IP set address name= "% network card name%" Source=static addr=192.168.1.215 mask=255.255.255.0
Netsh-c interface IP set address name= "% network card name%" gateway=192.168.1.1 gwmetric=0
Netsh-c interface IP Add DNS name= "% network card name%" addr=202.96.209.133 index=1
Netsh-c interface IP Add DNS name= "% network card name%" addr=202.96.209.5 index=2

Just tested the next, if there are two network adapters, will modify the local connection after the number of smaller, such as two local connections, the name is local connection 2, and local connection 3, the script will modify the local connection 2, and can not correctly identify the active network card, so it is not perfect, can only wait for LZ to help improve the I'm not capable of that.

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.