經常在不同網路環境(公司、家裡、咖啡廳)切換固定 IP,手動設定繁瑣。
ChangeIP.bat。@echo off
rem 網卡名稱,可在「網路連線」中查看,例如「無線網路連線」
set eth="無線網路連線"
rem 目標 IP
set ip=192.168.1.8
rem 閘道
set gw=192.168.1.1
rem 子網路遮罩
set netmasks=255.255.255.0
echo 正在將本機 IP 變更為 %ip%
if %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% > nul
if not %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% 1 > nul
echo ....................
echo 檢查目前 IP:
ipconfig
echo ....................
echo 成功將 IP 變更為 %ip%!
pause
close

建立多個 .bat 檔對應不同環境,命名清楚(如 IP_Company.bat、IP_Home.bat)即可一鍵切換。