Test
@echo off
setlocal
:: --- AYARLAR (Burayı kendi sisteminize göre düzenleyin) ---
set TARGET_IP=192.168.1.100
set TARGET_PORT=8080
set SERVICE_NAME=HizmetinizinTamAdi
:: ----------------------------------------------------------
echo [%date% %time%] %TARGET_IP%:%TARGET_PORT% adresi kontrol ediliyor...
:: PowerShell ile TCP bağlantı kontrolü (Hızlı yanıt alabilmek için TcpClient kullanıyoruz)
powershell -NoProfile -Command "$tcp = New-Object System.Net.Sockets.TcpClient; try { $tcp.Connect('%TARGET_IP%', %TARGET_PORT%); $tcp.Close(); exit 0 } catch { exit 1 }"
if %ERRORLEVEL% EQU 0 (
echo [%date% %time%] Yayinda sorun yok. Port %TARGET_PORT% acik ve yanit veriyor.
) else (
echo [%date% %time%] HATA: %TARGET_IP%:%TARGET_PORT% adresinde yayin bulunamadi!
echo [%date% %time%] "%SERVICE_NAME%" hizmeti yeniden baslatiliyor...
:: Hizmeti durdur ve başlat
net stop "%SERVICE_NAME%"
:: Hizmetin tam kapanması için 3 saniye bekleme süresi
timeout /t 3 /nobreak >nul
net start "%SERVICE_NAME%"
echo [%date% %time%] Islem tamamlandi.
)
endlocal