Bat脚本自动设置本机IP地址

@echo off
color 4

title  以Admin权限设置本机IP地址

PUSHD %~DP0 & cd /d “%~dp0”
%1 %2
mshta vbscript:createobject(“shell.application”).shellexecute(“%~s0″,”goto :runas”,””,”runas”,1)(window.close)&goto :eof

:runas

echo  a:公司IP设置,b:家用IP随机设置

set/p c=

if /i “%c%” equ “a” goto company

if /i “%c%” equ “b” goto home

:company

echo  正在设置固定IP(192.168.xx.xx),请稍后…

netsh interface ipv4 set address name=”WLAN” source=static addr=192.168.xx.xx mask=255.255.255.0 gateway=192.168.xx.1 gwmetric=0 >nul

echo  正在添加本机主DNS…

netsh interface ipv4 set dns name=”WLAN” source=static addr=114.114.114.114 register=PRIMARY

goto printip

goto end

:home

echo 正在自动获取IP地址…

netsh interface ip set address name = “WLAN” source = dhcp

echo 正在自动获取DNS服务器…

netsh interface ip set dns name = “WLAN” source = dhcp

goto printip

goto end

:printip

color 3

echo   查看本机当前IP配置

ipconfig /all

echo  停顿6秒后结束

ping /n 6 127.1>nul

exit
pause
 

    原文作者:秋叶华
    原文地址: https://blog.csdn.net/u014614478/article/details/122774145
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞