Security

Reply
MVP
Posts: 123
Registered: ‎07-13-2015

Simple script to save some time

Hello everyone,

 

If you are managing a wireless network and also do end user support, you might be interested with this script that I made to make my life easier and save some time. I mostly use it to save myself from remote desktop sessions or numerous phone calls.


The script will do the following :

- Create directory C:\wifi

- Save all output from "netsh wlan show all" command and "ipconfig -all" in a file name wifi_info.txt

- Connect to another SSID of your choice and save output to same file

- Give on screen directions for end user to send it back to your e-mail address

 

This is useful to gather informations about the endpoint's driver version or wi-fi adapter model. Also when you want to troubleshoot authentication problems, it will permit you to see if the client actually receives an IP address through DHCP or if it is configured statically for some reason, same for DNS servers. Most importantly, get the device's MAC address.

You will also be able to see channel, retransmits, BSSID on which it is currently associated. Also all neighboring BSSIDs from the client perspective. Also many more :) (try the command "netsh wlan show all" in cmd prompt if you don't know it and you might be surprised by all the output).

Good thing is that no admin rights are required so it fits any Windows laptops. 

I also added timers just to make sure it has the time to authenticate + get IP address.

 

You can take the following text and save it as a .bat file. If you want to e-mail it to end users, simply zip it or rename it to .txt - You can use a .bat to .exe converter too and zip it.

 

@echo off
mkdir C:\wifi
echo. > "C:\wifi\wifi_info.txt"
echo ***  Current Connection OUTPUT ***  >> "C:\wifi\wifi_info.txt"
netsh wlan show all >> "C:\wifi\wifi_info.txt"
ipconfig -all >> "C:\wifi\wifi_info.txt"
echo. >> "C:\wifi\wifi_info.txt"
echo *** SSID A OUTPUT ***  >> "C:\wifi\wifi_info.txt"
echo. >> "C:\wifi\wifi_info.txt"
netsh wlan connect name=SSID-A ssid=SSID-A >> "C:\wifi\wifi_info.txt"
@echo off
echo Connecting to SSID-A ...
echo.
echo 5
ping -n 2 127.0.0.1>nul
echo 4
ping -n 2 127.0.0.1>nul
echo 3
ping -n 2 127.0.0.1>nul
echo 2
ping -n 2 127.0.0.1>nul
echo 1
ping -n 2 127.0.0.1>nul
netsh wlan show interfaces >> "C:\wifi\wifi_info.txt"
ipconfig -all >> "C:\wifi\wifi_info.txt"
netsh wlan disconnect
@echo off
echo Exporting SSID-A Information to file ...
echo.
echo 3
ping -n 2 127.0.0.1>nul
echo 2
ping -n 2 127.0.0.1>nul
echo 1
ping -n 2 127.0.0.1>nul
echo. >> "C:\wifi\wifi_info.txt"
echo ***  SSID B OUTPUT ***  >> "C:\wifi\wifi_info.txt"
echo. >> "C:\wifi\wifi_info.txt"
netsh wlan connect name=SSID-B ssid=SSID-B >> "C:\wifi\wifi_info.txt"
@echo off
echo Connecting to SSID-B ...
echo.
echo 5
ping -n 2 127.0.0.1>nul
echo 4
ping -n 2 127.0.0.1>nul
echo 3
ping -n 2 127.0.0.1>nul
echo 2
ping -n 2 127.0.0.1>nul
echo 1
ping -n 2 127.0.0.1>nul
netsh wlan show interfaces >> "C:\wifi\wifi_info.txt"
ipconfig -all >> "C:\wifi\wifi_info.txt"
netsh wlan disconnect
@echo off
echo Exporting SSID-B Information to file ...
echo.
echo 3
ping -n 2 127.0.0.1>nul
echo 2
ping -n 2 127.0.0.1>nul
echo 1
ping -n 2 127.0.0.1>nul
@echo off
echo.
echo Please navigate to C:\wifi\ and copy the file named wifi_info.txt then send it to your_networking_team@company.com
echo.
pause

 

Cheers :D

 

ACMP, ACCP, BCNE
MVP
Posts: 123
Registered: ‎07-13-2015

Re: Simple script to save some time

I did some improvement to this script. Might interest some of you.

 

The following will ping the gateway of the device regardless of it's network as it stores it into a variable from route.exe output and then saves it to the same text file. This works with any adaptors name or windows language.

 

 

@echo please wait... 
::# Define a temp variable 'DefaultGateway' 
@For /f "tokens=3" %%* in ( 
   'route.exe print ^|findstr "\<0.0.0.0\>"' 
   ) Do @Set "DefaultGateway=%%*" 
 
 
::# Redirect output to a textfile 
@>> "c:\wifi\wifi_info.txt" ( 
  @echo [%Date% %time%] - %title% 
  @ping %DefaultGateway% 
) 

Also another simple addition was to test DNS resolution

 

ping DNS Entry >> "C:\wifi\wifi_info.txt"

Cheers :)

ACMP, ACCP, BCNE
Search Airheads
Showing results for 
Search instead for 
Did you mean: