How to know which SSID I am connected in Windows batch file?

限于喜欢 提交于 2021-02-04 21:01:00

问题


For now, I have 2 batch file which turns on and off proxy using Registry Editor

Like

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

But, I read some where that it is possible to turn on or off proxy based on the network you are connected? So, if I can get the SSID name I can keep this in if else condtion


回答1:


To simply get the SSID do:

netsh wlan show interface | findstr /i "SSID"

to set the first one as a variable use a for loop (assuming you do not want to use the mac address):

@echo off
for /f "tokens=3" %%i in ('netsh wlan show interface ^| findstr /i "SSID"') do set "myssid=%%i" & goto next
:next
set "myssid=%myssid: =%"
if /i "%myssid%"=="Spektrum" (
  reg add ....
)
if /i "%myssid%"=="someotherSSID" (
  reg add ....
)

To complete your code as is:

@echo off
for /f "tokens=3" %%i in ('netsh wlan show interface ^| findstr /i "SSID"') do set "myssid=%%i" & goto next
:next
echo %myssid%
set "myssid=%myssid: =%"
echo %myssid%
if /i "%myssid%"=="Spectrum" (
   echo "Spectrum"
 ) ELSE (
   echo "Other"
)


来源:https://stackoverflow.com/questions/54860323/how-to-know-which-ssid-i-am-connected-in-windows-batch-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!