@echo off
title Ag Teshis Raporu - Bilgisayar Borsasi
color 0B
setlocal enabledelayedexpansion

net session >nul 2>&1
if %errorlevel% neq 0 (
  echo.
  echo Yonetici yetkisi gerekiyor. Onay penceresinde EVET deyin...
  powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
  exit /b
)

set STAMP=
for /f %%I in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd-HHmm"') do set STAMP=%%I
if not defined STAMP set STAMP=rapor
set OUT=%USERPROFILE%\Desktop\Ag-Raporu-%STAMP%
if not exist "%OUT%" mkdir "%OUT%"
set R=%OUT%\ag-raporu.txt

cls
echo ============================================================
echo   AG TESHIS RAPORU
echo   bilgisayarborsasi.com.tr
echo ============================================================
echo.
echo  Bu arac SADECE OKUR ve TEST EDER. Hicbir ayari degistirmez.
echo  Sonuc: %R%
echo.
echo  Test suruyor, lutfen bekleyin (30-60 saniye)...
echo.

echo ==== AG TESHIS RAPORU ==== > "%R%"
echo Tarih: %date% %time% >> "%R%"
echo. >> "%R%"

echo [1/7] IP yapilandirmasi...
echo ---- 1. IPCONFIG /ALL ---- >> "%R%"
ipconfig /all >> "%R%" 2>&1
echo. >> "%R%"

echo [2/7] Varsayilan ag gecidi...
for /f "tokens=2 delims=:" %%G in ('ipconfig ^| findstr /i "Varsay Default Gateway"') do (
  for /f "tokens=1" %%H in ("%%G") do if not "%%H"=="" set GW=%%H
)
echo ---- 2. AG GECIDI: %GW% ---- >> "%R%"
if defined GW (
  ping -n 4 %GW% >> "%R%" 2>&1
) else (
  echo Ag gecidi bulunamadi - muhtemelen IP alinamiyor. >> "%R%"
)
echo. >> "%R%"

echo [3/7] Internet erisimi (IP ile)...
echo ---- 3. PING 8.8.8.8 ---- >> "%R%"
ping -n 4 8.8.8.8 >> "%R%" 2>&1
echo. >> "%R%"

echo [4/7] Ad cozumleme (DNS)...
echo ---- 4. NSLOOKUP google.com ---- >> "%R%"
nslookup google.com >> "%R%" 2>&1
echo. >> "%R%"
echo ---- 4b. PING google.com ---- >> "%R%"
ping -n 4 google.com >> "%R%" 2>&1
echo. >> "%R%"

echo [5/7] Yol izleme...
echo ---- 5. TRACERT 8.8.8.8 (ilk 10 atlama) ---- >> "%R%"
tracert -h 10 -w 800 8.8.8.8 >> "%R%" 2>&1
echo. >> "%R%"

echo [6/7] Proxy ve adaptor durumu...
echo ---- 6. WINHTTP PROXY ---- >> "%R%"
netsh winhttp show proxy >> "%R%" 2>&1
echo. >> "%R%"
echo ---- 6b. ADAPTORLER ---- >> "%R%"
powershell -NoProfile -Command "Get-NetAdapter | Select-Object Name,InterfaceDescription,Status,LinkSpeed | Format-Table -AutoSize | Out-String -Width 200" >> "%R%" 2>&1
powershell -NoProfile -Command "Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object InterfaceAlias,ServerAddresses | Format-Table -AutoSize | Out-String -Width 200" >> "%R%" 2>&1
echo. >> "%R%"

echo [7/7] Sistem saati ve kablosuz profil...
echo ---- 7. SAAT ---- >> "%R%"
echo Yerel saat: %date% %time% >> "%R%"
w32tm /query /status >> "%R%" 2>&1
echo. >> "%R%"
echo ---- 7b. WLAN ---- >> "%R%"
netsh wlan show interfaces >> "%R%" 2>&1

cls
echo ============================================================
echo   SONUC
echo ============================================================
echo.

set VERDICT=Belirsiz
ping -n 1 8.8.8.8 >nul 2>&1
if %errorlevel% equ 0 (set IPOK=1) else (set IPOK=0)
ping -n 1 google.com >nul 2>&1
if %errorlevel% equ 0 (set DNSOK=1) else (set DNSOK=0)

if "%IPOK%"=="1" if "%DNSOK%"=="1" set VERDICT=Ag ve DNS calisiyor. Sorun tarayici, proxy veya guvenlik yazilimi tarafinda olabilir.
if "%IPOK%"=="1" if "%DNSOK%"=="0" set VERDICT=DNS SORUNU. IP ile erisim var, ad cozumleme yok. DNS'i 1.1.1.1 yapin.
if "%IPOK%"=="0" if "%DNSOK%"=="0" set VERDICT=INTERNET ERISIMI YOK. Modem/hat veya IP (DHCP) tarafina bakin.

echo  %VERDICT%
echo.
if not defined GW echo  UYARI: Ag gecidi bulunamadi - modemden IP alinamiyor olabilir.
echo.
echo  Ayrintili rapor: %R%
echo.
echo  Duzeltme icin: ag-sifirlama.bat
echo  Rehber: bilgisayarborsasi.com.tr/rehber/internet-bagli-ama-yok
echo.
start "" "%OUT%"
pause
