Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get the Nic name by batch processing

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to obtain the network card name for batch processing. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.

The code is as follows:

:: Use ipconfig /all to get the name of the network card.

FOR /F "tokens=2*" %%i IN ('ipconfig/all^|find /i "Ethernet adapter "') DO set name=%%j

:: Use the for command to remove the colon after the network card name.

FOR /F "tokens=1* delims=:" %%i in ("%name%") do set NIC name =%%i

Apply the above script to modify DNS, for example, yesterday the national DNS server crashed, DNS changed to 202.96.199.132 to restore normal Internet access.

Modify DNS Fragments

The code is 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 NIC name =%%i

netsh -c interface ip add dns name="%NIC name %" addr=202.96.199.132 index=1

netsh -c interface ip add dns name="%NIC name %" addr=202.96.64.38 index=2

Modify IP, subnet mask, gateway, DNS code

The code is 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 NIC name =%%i

netsh -c interface ip set address name="%NIC name %" source=static addr=192.168.1.215 mask=255.255.255.0

netsh -c interface ip set address name="%NIC name %" gateway=192.168.1.1 gwmetric=0

netsh -c interface ip add dns name="%NIC name %" addr=202.96.209.133 index=1

netsh -c interface ip add dns name="%NIC name %" addr=202.96.209.5 index=2

About "batch processing how to get network card name" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report