切換 ip 批處理

來源:互聯網
上載者:User

自動擷取

@echo off
rem eth       //設定網卡名稱,如"本地串連"
set eth="無線網路串連"
rem sleep     //設定後面的等待時間,如"20秒"
set sleep=ping -n 8 127.0.0.1>nul 2>nul
echo 正在更改為自動擷取IP地址...
netsh interface ip set address "%eth%" source=dhcp
echo 正在更改為自動擷取DNS地址...
netsh interface ip set dns "%eth%" source=dhcp
echo --------------------------------------
echo   更改完畢,正在自動擷取IP,等待10秒
echo --------------------------------------
%SLEEP%
echo ----------------------------------------
echo   檢查當前IP,如無法擷取請聯絡網管
echo ----------------------------------------
ipconfig /all
pause
close

 

設定固定值

@echo off
rem eth       //設定網卡名稱,如"本地串連"
set eth="無線網路串連"
rem ip         //設定IP地址
set ip=192.168.1.243
rem gw         //設定網關
set gw=192.168.1.1
rem netmasks   //設定子網路遮罩
set netmasks=255.255.255.0
rem dns1       //設定主DNS
set dns1=192.168.1.1
rem dns2       //設定輔DNS
set dns2=192.168.1.1
echo 正在將本機IP更改到:%ip%
netsh interface ip set address "%eth%" static %ip% %netmasks% %gw%
echo 正在添加本機主DNS:%dns1%
netsh interface ip set dns "%eth%" static %dns1%
echo 正在添加本機副DNS:%dns2%
netsh interface ip add dns "%eth%" %dns2%
echo ------------------------------
echo   IP更改完畢,檢查當前配置...
echo ------------------------------
ipconfig /all
pause
close

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.