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.