Windows下命令行切换wifi 网络配置脚本

哈哈第一次写bat脚本, 如果有需要的直接拿吧



@echo off

REM 当wifi为XXXXXX时  指定静态ip  配置代理

set union_nfq=XXXXXX 

set wifi_name=%1

set proxy_ip=http://192.1.2.3:808

if %wifi_name% equ %union_nfq% (

netsh wlan connect UNIONNFQ

REM 开启代理

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f

REM 配置代理ip端口

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "192.1.2.3:808" /f

rem “对于本地地址不使用代理服务器”这个勾,不会勾选上

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "192.1.2.*;192.1.5.*;192.1.8.*;" /f

rem “对于本地地址不使用代理服务器”这个勾,会勾选上

::reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "192.1.2.*;192.1.5.*;192.1.8.*;" /f

REM ip4 配置

netsh interface ip set address name="WLAN" source= static 192.1.2.132 255.255.255.0 192.1.2.254

netsh interface ip set dnsservers name="WLAN" source= static address= 192.1.5.82 register= both validate= no

npm config set proxy %proxy_ip% --global

npm config set https-proxy %proxy_ip% --global

git config --global http.proxy %proxy_ip%

git config --global https.proxy %proxy_ip%

) else (

netsh wlan connect %wifi_name%

REM 关闭代理

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f

REM 自动获取ip

netsh interface ip set address name="WLAN" source= dhcp

netsh interface ip set dnsservers name="WLAN" source=dhcp

npm config delete proxy --global

npm config delete https-proxy --global

git config --global --unset http.proxy

git config --global --unset https.proxy

)

PAUSE



使用愉快 嘻嘻

你可能感兴趣的:(Windows下命令行切换wifi 网络配置脚本)