Wednesday, 21 September 2016

Getting Data Out of the Windows ‘netsh wlan show interfaces’ Command

I recently read a very nice article by Matt Frederick about using a Windows command prompt utility to gain information about what your Windows wireless adapter is up to while connected to a Wi-Fi network ( https://finesine.com/2016/09/17/using-netsh-wlan-show-interfaces-to-monitor-associationroaming/)


In  Matt’s article, he described how he wrapped the ‘netsh’ command into a nice little batch file to run the command regularly, allowing information to be presented in a more dynamic fashion.


I was so impressed with the information provided by the utility, that I decided I’d  try to get the information it provides into a more usable format. In short, I hacked together a Windows Powersell script that runs the ‘netsh’ CLI utility regularly and parses the output data into a CSV format.

By piping the output into a file, you can get a nice CSV file that can be opened in Excel to look at the raw data over a period of time. It’s great for looking at the adapter signal level and BSSID information - it’s easy to spot when your client roams and the approximate signal level at which this takes place.


Fig 1 - You can get output like this...unless you've got good eye-sight, it's better in a CSV :)


A few caveats:


  • I’m not  a coder - this is my first Powershell script
  • This isn’t a robust piece of supported code - it will break easily over time when the output of the ‘netsh’ command changes (refer to the previous bullet)
  • The ‘netsh’ utility natively provides RSSI data as  percentage figure. I’ve converted it to dBm in the script, but the highest dBm figure you’ll ever see is 50dBm ( which is 100% in the ‘netsh’ utility output)...don’t shoot the messenger on that one.
  • This was a bit of fun to do - have fun with it yourself, but don’t get too angry if it doesn't work for you :)
  • Open the script file with Notepad and read ALL of the notes at the top of the file that explain how to use the script.


There are a few challenges getting the script to run without lots of warnings in Powershell - open the script file and read the notes at the top of the file.


By default, the script runs every second, which is nice to roam around and capture regular data. Change the variable ‘$SleepInterval’ at the beginning of the code if you’d like to extend it to a more infrequent interval (2 = 2 secs, 3 = 3 secs etc…)

Again, have fun with it...oh yes, you can find the script here: https://github.com/wifinigel/win-wlan-data-script

References: