@echo off
title DNS Onarim Araci - Bilgisayar Borsasi
color 0B
setlocal

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 "DESK=%USERPROFILE%\Desktop"
for /f "usebackq delims=" %%D in (`powershell -NoProfile -Command "[Environment]::GetFolderPath('Desktop')"`) do set "DESK=%%D"
set "OUT=%DESK%\DNS-Onarim-Raporu.txt"

:menu
cls
echo ============================================================
echo   DNS ONARIM ARACI  -  Windows 10 / Windows 11
echo   bilgisayarborsasi.com.tr
echo ============================================================
echo.
echo   1. Sadece TEST et (hicbir ayar degismez)
echo   2. Hizli DNS onarimi + DNS'i 1.1.1.1 / 8.8.8.8 yap  (ONERILEN)
echo   3. Tam ag yigini sifirlama (Winsock + TCP/IP + proxy)
echo   4. DNS'i eski haline al (modemden otomatik)
echo   5. Cikis
echo.
echo  Once 1 ile test edin. Sorun DNS cikarsa 2'yi secin.
echo  2 ise yaramazsa 3'u secin (yeniden baslatma ister).
echo.
choice /c 12345 /n /m "Seciminiz (1-5): "
if errorlevel 5 exit /b
if errorlevel 4 goto geri
if errorlevel 3 goto tam
if errorlevel 2 goto hizli
goto sadecetest

:test
echo.
echo  --- BAGLANTI TESTI ---
powershell -NoProfile -Command "$ip = Test-Connection 8.8.8.8 -Count 2 -Quiet; $dns = $true; try { Resolve-DnsName google.com -DnsOnly -Type A -ErrorAction Stop | Out-Null } catch { $dns = $false }; if ($ip) { Write-Host '  Internete ulasim (8.8.8.8 ping) : VAR' -ForegroundColor Green } else { Write-Host '  Internete ulasim (8.8.8.8 ping) : YOK' -ForegroundColor Red }; if ($dns) { Write-Host '  Ad cozumleme (DNS)              : CALISIYOR' -ForegroundColor Green } else { Write-Host '  Ad cozumleme (DNS)              : HATALI' -ForegroundColor Red }; if ($ip -and -not $dns) { Write-Host '  SONUC: Internet var, DNS bozuk. 2. secenek bu sorunu cozer.' -ForegroundColor Yellow } elseif (-not $ip) { Write-Host '  SONUC: Internete hic ulasilamiyor. Modem/hat veya ag karti kontrol edilmeli; 3. secenegi deneyin.' -ForegroundColor Yellow } else { Write-Host '  SONUC: Internet ve DNS calisiyor. Sorun tarayicida olabilir (onbellek, eklenti, proxy).' -ForegroundColor Yellow }"
echo.
exit /b

:rapor
echo ==== DNS ONARIM RAPORU - %date% %time% ==== > "%OUT%"
echo. >> "%OUT%"
ipconfig /all >> "%OUT%" 2>&1
netsh winhttp show proxy >> "%OUT%" 2>&1
powershell -NoProfile -Command "Get-DnsClientServerAddress | Where-Object { $_.ServerAddresses } | Format-Table InterfaceAlias, AddressFamily, ServerAddresses -AutoSize | Out-String -Width 200" >> "%OUT%" 2>&1
exit /b

:sadecetest
call :test
echo  Ayrintili ag bilgisi kaydediliyor...
call :rapor
echo  Rapor: %OUT%
echo.
pause
goto menu

:hizli
cls
echo ============================================================
echo   HIZLI DNS ONARIMI
echo ============================================================
echo.
echo  [1/6] Mevcut ayarlar yedekleniyor...
call :rapor
echo        TAMAM - %OUT%
echo  [2/6] DNS onbellegi temizleniyor...
ipconfig /flushdns >nul 2>&1
echo        TAMAM
echo  [3/6] ARP tablosu temizleniyor...
netsh interface ip delete arpcache >nul 2>&1
echo        TAMAM
echo  [4/6] IP adresi yenileniyor (baglanti birkac saniye kopabilir)...
ipconfig /release >nul 2>&1
ipconfig /renew >nul 2>&1
echo        TAMAM
echo  [5/6] Aktif baglantinin DNS'i 1.1.1.1 ve 8.8.8.8 yapiliyor...
powershell -NoProfile -Command "$n = Get-NetIPConfiguration | Where-Object { $_.IPv4DefaultGateway -and $_.NetAdapter.Status -eq 'Up' }; if (-not $n) { Write-Host '        Aktif baglanti bulunamadi, DNS degistirilmedi.' -ForegroundColor Red } else { foreach ($i in $n) { Set-DnsClientServerAddress -InterfaceIndex $i.InterfaceIndex -ServerAddresses ('1.1.1.1','8.8.8.8','2606:4700:4700::1111','2001:4860:4860::8888'); Write-Host ('        TAMAM - ' + $i.InterfaceAlias) } }"
echo  [6/6] DNS kaydi yenileniyor...
ipconfig /flushdns >nul 2>&1
ipconfig /registerdns >nul 2>&1
echo        TAMAM
echo.
echo  Baglantinin oturmasi icin 5 saniye bekleniyor...
ping -n 6 127.0.0.1 >nul
call :test
echo  Tarayicinizi KAPATIP yeniden acin, sonra siteleri deneyin.
echo  Eski ayarlariniz: %OUT%
echo  Geri almak icin bu araci tekrar calistirip 4'u secin.
echo.
pause
goto menu

:tam
cls
echo ============================================================
echo   TAM AG YIGINI SIFIRLAMA
echo ============================================================
echo.
echo  Winsock, TCP/IP ve proxy ayarlari fabrika durumuna doner.
echo  Kayitli Wi-Fi sifreleriniz SILINMEZ.
echo  Elle girilmis SABIT IP, SABIT DNS ve PROXY ayarlari SILINIR.
echo  Islem sonunda YENIDEN BASLATMA gerekir.
echo.
choice /c EH /n /m "Devam edilsin mi? (E=Evet / H=Hayir): "
if errorlevel 2 goto menu
echo.
echo  [1/5] Mevcut ayarlar yedekleniyor...
call :rapor
echo        TAMAM - %OUT%
echo  [2/5] DNS onbellegi ve IP kirasi...
ipconfig /flushdns >nul 2>&1
ipconfig /release >nul 2>&1
ipconfig /renew >nul 2>&1
echo        TAMAM
echo  [3/5] Winsock katmani sifirlaniyor...
netsh winsock reset >nul 2>&1
echo        TAMAM
echo  [4/5] TCP/IP yigini sifirlaniyor...
netsh int ip reset >nul 2>&1
netsh int ipv4 reset >nul 2>&1
netsh int ipv6 reset >nul 2>&1
netsh int tcp reset >nul 2>&1
echo        TAMAM
echo  [5/5] Proxy ayari temizleniyor...
netsh winhttp reset proxy >nul 2>&1
echo        TAMAM
echo.
echo  BILGISAYARI SIMDI YENIDEN BASLATIN. Yeniden baslatmadan etkili olmaz.
echo  Eski ayarlariniz: %OUT%
echo.
choice /c EH /n /m "Simdi yeniden baslatilsin mi? (E=Evet / H=Hayir, sonra yaparim): "
if errorlevel 2 goto son
shutdown /r /t 15 /c "Ag ayarlari sifirlandi, bilgisayar yeniden baslatiliyor."
echo.
echo  15 saniye icinde yeniden baslatilacak. Iptal icin: shutdown /a
goto son

:geri
cls
echo ============================================================
echo   DNS'I ESKI HALINE ALMA (OTOMATIK)
echo ============================================================
echo.
powershell -NoProfile -Command "$n = Get-NetIPConfiguration | Where-Object { $_.NetAdapter.Status -eq 'Up' }; foreach ($i in $n) { Set-DnsClientServerAddress -InterfaceIndex $i.InterfaceIndex -ResetServerAddresses; Write-Host ('  TAMAM - ' + $i.InterfaceAlias + ' : DNS modemden otomatik alinacak') }"
ipconfig /flushdns >nul 2>&1
echo.
echo  DNS ayari otomatige alindi.
echo.
pause
goto menu

:son
echo.
echo  Rehber: bilgisayarborsasi.com.tr/rehber/dns-sunucusu-yanit-vermiyor
echo.
pause
