1

I'm trying to get wifi Channel output from netsh command to be 2.4GHz or 5GHz

The following provides me with Channel output:

netsh wlan show interface name=Wi-Fi | findstr "Channel"

Output is "Channel : 161"

2.4GHz = (Channel 1 - 11) OR 5GHz = (Channel 36 - 177)

I am having problems in a batch file to save the netsh output to a variable and then evaluate the variable, if <=11 it's 2GHz OR >= 36 but <=177 it's 5GHz

Any help is appreciated!

3
  • for /f "tokens=2 delims=:" %%r in ('netsh wlan show interface name=WiFi^|findstr "Channel"') do Set Channel=%%r This will leave a space before the %%r but you shouldn't need to trim it for your use. Add a echo "%Channel%" to see the results. I could write this whole batch file for you but I HIGHLY suggest that you take the tidbit I gave you and solve the rest. Use if /? to figure out the greater than and less than logic. Commented Jan 20, 2022 at 23:10
  • I got it to work if wi-fi is enabled, however, if not enabled I get output "36 was expected at this time." @echo off for /f "tokens=2 delims=:" %%r in ('netsh wlan show interface name=Wi-Fi ^| findstr "Channel"') do Set Channel=%%r if %Channel% GEQ 36 if %Channel% LEQ 177 (echo Wi-Fi 5GHz) else (if %Channel% GEQ 1 if %Channel% LEQ 11 (echo Wi-Fi 2.4GHz) ) if "%Channel%"=="" (echo Wi-Fi not enabled) set "Channel="
    – mnauta
    Commented Jan 21, 2022 at 13:47
  • Thanks @iTwasnTme. I thought of that too. (great minds blah blah blah). I was trying to make it as simple as possible by slightly tweaking his/her code directly as it was. This line runs without error on my machine and I didn't need to escape the eq. Commented Jan 21, 2022 at 15:20

1 Answer 1

0

Got the script to work just as I needed it, now I can use it in our RMM tool. @SeñorCMasMas thanks for the initial help

@echo off
setlocal ENABLEDELAYEDEXPANSION

for /f "tokens=2 delims=:" %%r in ('netsh wlan show interface name=Wi-Fi ^| findstr "Channel"') do Set Channel=%%r

if [!Channel!] EQU []  (echo Wi-Fi Not Connected) 
if !Channel! GEQ 36 if !Channel! LEQ 177 (echo 5GHZ)
if !Channel! GEQ 1 if !Channel! LEQ 11 (echo 2.4GHZ)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .