@echo off
setlocal
title FORNS - Find your DNS
net session >nul 2>&1
if not %errorlevel%==0 (
  echo Administrator privileges are required
  powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
  exit /b
)
:menu
cls
echo.
echo   FORNS - Find your DNS
echo   =====================
echo.
echo   1  Cloudflare    1.1.1.1
echo   2  Google        8.8.8.8
echo   3  Quad9         9.9.9.9
echo   4  AdGuard       94.140.14.14
echo   5  AliDNS        223.5.5.5
echo   6  DNSPod        119.29.29.29
echo   7  Baidu DNS     180.76.76.76
echo   8  Automatic DNS
echo   9  Show current DNS
echo   F  Flush DNS cache
echo   0  Exit
echo.
set /p choice=Choose an option: 
if "%choice%"=="1" (set "dns=1.1.1.1,1.0.0.1"&set "name=Cloudflare"&goto apply)
if "%choice%"=="2" (set "dns=8.8.8.8,8.8.4.4"&set "name=Google"&goto apply)
if "%choice%"=="3" (set "dns=9.9.9.9,149.112.112.112"&set "name=Quad9"&goto apply)
if "%choice%"=="4" (set "dns=94.140.14.14,94.140.15.15"&set "name=AdGuard"&goto apply)
if "%choice%"=="5" (set "dns=223.5.5.5,223.6.6.6"&set "name=AliDNS"&goto apply)
if "%choice%"=="6" (set "dns=119.29.29.29"&set "name=DNSPod"&goto apply)
if "%choice%"=="7" (set "dns=180.76.76.76"&set "name=Baidu DNS"&goto apply)
if "%choice%"=="8" goto automatic
if "%choice%"=="9" goto current
if /i "%choice%"=="F" goto flush
if "%choice%"=="0" exit /b
goto menu
:apply
powershell -NoProfile -Command "$a=Get-NetAdapter|Where-Object {$_.Status -eq 'Up' -and $_.HardwareInterface}; if(-not $a){throw 'No active adapters found'}; $a|ForEach-Object {Set-DnsClientServerAddress -InterfaceIndex $_.ifIndex -ServerAddresses '%dns%'.Split(',')}"
if errorlevel 1 goto failed
echo.
echo DNS changed to %name%
goto done
:automatic
powershell -NoProfile -Command "$a=Get-NetAdapter|Where-Object {$_.Status -eq 'Up' -and $_.HardwareInterface}; if(-not $a){throw 'No active adapters found'}; $a|ForEach-Object {Set-DnsClientServerAddress -InterfaceIndex $_.ifIndex -ResetServerAddresses}"
if errorlevel 1 goto failed
echo.
echo Automatic DNS restored
goto done
:current
powershell -NoProfile -Command "Get-NetAdapter|Where-Object {$_.Status -eq 'Up' -and $_.HardwareInterface}|ForEach-Object {$d=Get-DnsClientServerAddress -InterfaceIndex $_.ifIndex -AddressFamily IPv4; [PSCustomObject]@{Adapter=$_.Name;DNS=$d.ServerAddresses -join ', '}}|Format-Table -AutoSize"
goto done
:flush
ipconfig /flushdns
goto done
:failed
echo.
echo The DNS operation failed
:done
echo.
pause
goto menu
