Windows下自動切換IP腳本

在不同環境使用電腦經常要切換IP,利用netsh interface ip命令可以輕鬆切換IP和DNS:

     netsh interface ip有以下命令:

     add            - 在一個表格中添加一個配置項。
     delete         - 從一個表格中刪除一個配置項。
     dump           - 顯示一個配置腳本。
     help           - 顯示命令列表。
     install        - 安裝 IP 協議。
     reset          - 重置 IP 配置。
     set            - 設置配置信息。
     show           - 顯示信息。
     uninstall      - 卸載 IP 協議。

 

     netsh interface IP set有以下的命令:
     set address    - 設定通向接口的 IP 地址或默認網關。
     set compartment - 修改分段配置參數。
     set dnsservers - 設置 DNS 服務器模式和地址。
     set dynamicportrange - 修更改態端口分配所使用端口的範圍。
     set global     - 修改全局配置常規參數。
     set interface  - 修改 IP 的接口配置參數。
     set neighbors  - 設置鄰居地址。
     set route      - 修改路由參數。
     set subinterface - 修改子接口配置參數。
     set winsservers - 設置 WINS 服務器模式和地址。

 

     簡單示例1:設置固定IP,保存爲bat文件

   @echo off
   @rem 設置IP爲192.168.0.1,子網掩碼爲255.255.255.0,默認網關爲192.168.0.254
   netsh interface ip set address local static 192.168.0.1 255.255.255.0 192.168.0.254
   @rem 設置首選的DNS服務器192.168.0.254
   netsh interface ip set dns local 192.168.0.254
   @rem 添加DNS服務器202.106.196.115
   netsh interface ip add dns local 202.106.196.115 index=2

 

    示例2:自動獲取

   @echo off
   netsh interface ip set address name="local" source=dhcp
   netsh interface ip set dns name="local" source=dhcp
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章