::用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