REM Remap Panel and domains to the new IP
sc query plesksrv | find "STATE" | find "RUNNING"
IF %ERRORLEVEL% GTR 0 timeout 60 > NUL

"%plesk_bin%\reconfigurator" --remap-ips
"%plesk_bin%\ipmanage" --reread

REM Get instance external IP
for /f "tokens=*" %%i IN ('"%plesk_bin%\amazon\curl" http://169.254.169.254/latest/meta-data/public-ipv4') DO set EXTERNAL_IP=%%i
echo EXTERNAL_IP: %EXTERNAL_IP%

setlocal enabledelayedexpansion
for /f "tokens=6 delims= " %%i IN ('"%plesk_bin%\ipmanage.exe" -l') DO (
	set "INTERNAL_IP="
	echo %%i | find "." > temp
	set /p INTERNAL_IP="" < temp
	del temp

	echo InternalIP: !INTERNAL_IP!
	if "!INTERNAL_IP!" NEQ "" (
		echo IP is not empty...

		echo %EXTERNAL_IP% > temp
		set /p EXT_IP="" < temp
		del temp		

		if "!INTERNAL_IP!" NEQ "!EXT_IP!" (
			echo Reconfigure ip...
			call amazon_repair_ip.cmd !INTERNAL_IP!
			exit /b
		)
	)
)
endlocal