@echo off
IF EXIST iplist.txt DEL /F iplist.txt
IF EXIST iplist_failed.txt DEL /F iplist_failed.txt
for /f "delims== tokens=1,2" %%G in (settings.cfg) do set %%G=%%H

FOR /L %%A IN (%IPSTART%,1,%IPEND%) DO (
	%CD%\bin\curl.exe --connect-timeout 2 -s -f --user root:%ASICWEBPASS% -X GET %IPNETWORK%.%%A/cgi-bin/get_system_info.cgi --anyauth | findstr /C:"Antminer S9k" >nul 2>&1
	if not errorlevel 1 (
		Echo [+] Found Antminer S9k.. Try unlock it..
		%CD%\bin\curl.exe --connect-timeout 2 -s -f -X POST --digest --user root:%ASICWEBPASS% %IPNETWORK%.%%A/cgi-bin/create_log_backup.cgi -d "/null /config/dropbear -sf"
        if not errorlevel 1 (
            Echo [+] Connect: %IPNETWORK%.%%A Success.. 
            Echo %IPNETWORK%.%%A>> iplist.txt
            %CD%\bin\curl.exe --connect-timeout 2 -s -f -X GET --digest --user root:%ASICWEBPASS% %IPNETWORK%.%%A/cgi-bin/reboot.cgi 
        ) else (
            Echo [!] %IPNETWORK%.%%A - Unlock failed!
            Echo %IPNETWORK%.%%A - Unlock failed! >> iplist_failed.txt
        )
    ) else (
        Echo [!] %IPNETWORK%.%%A - Antminer not found
        Echo %IPNETWORK%.%%A - Antminer not found >> iplist_failed.txt
    )
)

pause