萬盛學電腦網

 萬盛學電腦網 >> 電腦入門 >> Win批處理開機如何自動設置IP地址 電腦技術吧

Win批處理開機如何自動設置IP地址 電腦技術吧

@echo off 
REM select=1,網卡IP將被設置成172.16.200.34,select=2,網卡IP將被設置成192.168.0.5 
ping -n 2 192.168.0.254 && set select=2 || set select=1 
REM 獲取網卡名稱 
for /f "skip=4 tokens=3* delims= " %%i in ('ipconfig') do ( 
set adapter=%%i 
goto out 


:out 
set adapter=%adapter::=% 
if %select%==1 ( 
netsh int ip set address name="%adapter%" static 172.16.200.34 255.255.255.0 172.16.200.1 1 
netsh int ip set dns name="%adapter%" static 202.102.224.68 primary 
netsh int ip add dns name="%adapter%" 202.102.227.68 index=2 
) else ( 
netsh int ip set address name="%adapter%" static 192.168.0.5 255.255.255.0 192.168.0.254 1 


echo 設置完成,按任意鍵退出! 
pause >nul 2>nul
    copyright © 萬盛學電腦網 all rights reserved