切换 ip 批处理

本教程详细介绍了如何使用批处理脚本自动配置网络参数,并实现IP地址的自动获取,包括设置网卡名称、IP地址、网关、子网掩码、DNS等关键信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自动获取

@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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值