Windows 网络管理 - Batch

Windows 网络管理 - Batch

常用命令

REM 显示可用无线网络详情
netsh wlan show networks mode=bssid

REM 显示已配置无线网络
netsh wlan show profiles

REM 显示已安装无线网卡
netsh wlan show interface

REM 指定无线网卡连接指定无线网络
netsh wlan connect name="Internet" interface="Wi-Fi"

端口转发

REM 转发 Projector in WSL
netsh interface portproxy add v4tov4 listenport=19999 listenaddress=0.0.0.0 connectport=9999 connectaddress=127.0.0.1

常用脚本

自动连接 WIFI

直接定时连接 WIFI 会造成现有连接断开,可用通过以下脚本判断当前状况后决定是否需要连接:

netsh interface show interface | findstr /C:"Enabled        Disconnected   Dedicated        WLAN_INTERFACE_NAME" > C:\batch\connecting.txt

for /f "delims=" %%i in (C:\batch\connecting.txt) do (
  netsh wlan connect name="WIFI_SSID" interface="WLAN_INTERFACE_NAME"
)
Author: njun
njun's picture
Updated: 2021/08/28