bat文件-网络IP更换(适配各品牌笔记本网络地址快速切换)

老冯 运维笔记评论372阅读模式

做为运维、技术人员,或移动办公人员,经常要搬着笔记本电脑往返公司办公、家庭加班,但是,公司的IP经常是特定的,家里的还好(DHCP自动获取)。那么有没有办法快速切换呢?

我们可以设计一个bat批处理文件,只要在不同的办公环境下,根据提示操作即可:

@echo off
color 3f
mode con cols=80 lines=30
title 自动IP地址切换脚本
if "%1"=="1" goto ads
if "%1"=="2" goto office
if "%1"=="3" goto Home
if "%1"=="4" goto dhcp
:start
cls
echo=
echo =========================书==酷==网==络==设==置=============================
echo=
echo    1.切换到办公AD域-192.168.10.58
echo=
echo    2.切换到办公室IP-192.168.10.112
echo=
echo    3.切换到家里的IP-192.168.1.111
echo=
echo    4.切换到自动获取
echo=
echo    0.退出脚本
echo=
echo ============================================================================
echo=
set choice=
set /p choice=请输入你的选择:
if "%choice%"=="1" goto ads
if "%choice%"=="2" goto office
if "%choice%"=="3" goto Home
if "%choice%"=="4" goto dhcp
if "%choice%"=="0" exit
echo 输入有误,请重新选择!
pause>nul
goto start

:ads
cls
cls
echo.
echo 正在设置IP为办公ADS域请等待...
echo.
set net_interface="以太网"
echo 设置IP中...
netsh interface ip set address name="%net_interface%" source=static addr=192.168.10.58 mask=255.255.254.0 gateway=192.168.10.1 gwmetric=1
echo 设置IP成功...设置DNS中...
netsh interface ip set dns name="%net_interface%" source=static addr=192.168.10.212
echo IP已成功切换到办公ADS域设置,任意键返回...
pause>nul
goto start
 
:office
cls
cls
echo.
echo 正在设置IP为办公IP请等待...
echo.
set net_interface="以太网"
echo 设置IP中...
netsh interface ip set address name="%net_interface%" source=static addr=192.168.10.112 mask=255.255.254.0 gateway=192.168.10.1 gwmetric=1
echo 设置IP成功...设置DNS中...
netsh interface ip set dns name="%net_interface%" source=static addr=222.246.129.80
netsh interface ip add dns name="%net_interface%" 114.114.114.114 index=2
echo IP已成功切换到办公设置,任意键返回...
pause>nul
goto start
 
:Home
cls
echo.
echo 正在设置为家用IP请等待...
echo.
set net_interface="以太网"
echo 设置IP中...
netsh interface ip set address name="%net_interface%" source=static addr=192.168.1.111 mask=255.255.255.0  gateway=192.168.1.1 gwmetric=1
echo 设置IP成功...设置DNS中...
netsh interface ip set dns name="%net_interface%" source=static addr=222.246.129.80
netsh interface ip add dns name="%net_interface%" 114.114.114.114 index=2
echo IP已成功切换到办公设置,任意键返回...
pause>nul
goto start
 
:DHCP
echo.
echo 正在设置IP为自动获取,请等待...
echo.
set net_interface="以太网"
echo 设置IP中...
netsh interface ip set address name="%net_interface%" source=dhcp
echo 设置网关成功...设置DNS中...
netsh interface ip set dns name="%net_interface%" source=dhcp
echo 设置成功!按任意键返回选择菜单。
pause>nul
GOTO start

注意:保存字符集为ANSI,不能是UTF8。扩展名.bat。

具体修改内容(如IP地址、DNS等),请参看代码!

声明:若本文标注有“转载链接”或明文说明为“转载”,则为非本站作品,请保留原文链接;若未备注转载,则为老冯笔记作品,转载时请保留本文链接。

weinxin
fengquanjia
老冯的微信
微信扫一扫,关注老冯,获得更多办公知识,更多晨草/书酷的动态!
 
老冯
  • 本文由 老冯 发表于 2023年12月5日 16:46:18
  • 转载请务必保留本文链接:http://www.fengquanjia.cn/ip-qiehuan/
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定