::用ipconfig /all命令获取网卡名称。 FOR /F "tokens=2*" %%i IN ('ipconfig/all^|find /i "Ethernet adapter "') DO set name=%%j ::用for命令删除网卡名称后面的冒号。 FOR /F "tokens=1* delims=:" %%i in ("%name%") do set 网卡名称=%%i
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 网卡名称=%%i netsh -c interface ip add dns name="%网卡名称%" addr=202.96.199.132 index=1 netsh -c interface ip add dns name="%网卡名称%" addr=202.96.64.38 index=2
修改IP、子网掩码、网关、DNS代码
复制代码 代码如下:
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 网卡名称=%%i netsh -c interface ip set address name="%网卡名称%" source=static addr=192.168.1.215 mask=255.255.255.0 netsh -c interface ip set address name="%网卡名称%" gateway=192.168.1.1 gwmetric=0 netsh -c interface ip add dns name="%网卡名称%" addr=202.96.209.133 index=1 netsh -c interface ip add dns name="%网卡名称%" addr=202.96.209.5 index=2