Skip to content

Instantly share code, notes, and snippets.

@langheran
Created April 17, 2026 20:57
Show Gist options
  • Select an option

  • Save langheran/43e1ed6fcd34cf685605b52e685a8066 to your computer and use it in GitHub Desktop.

Select an option

Save langheran/43e1ed6fcd34cf685605b52e685a8066 to your computer and use it in GitHub Desktop.
C:\Users\NisimHurst\Home\scripts\secure_dns.ps1
@echo off
setlocal
set "PS1=%~dp0Clear-DomainCache.ps1"
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%PS1%" -Domain "cdn.storageimagedisplay.com" -BlockDomain
exit /b %errorlevel%
param(
[Parameter(Mandatory=$true)]
[string]$Domain,
[switch]$BlockDomain
)
Write-Host "=== Limpieza de caché para dominio: $Domain ===" -ForegroundColor Cyan
# 1. Flush DNS cache (global)
Write-Host "[1] Limpiando DNS cache..."
try {
Clear-DnsClientCache
Write-Host "DNS cache limpiado"
} catch {
Write-Warning "Error limpiando DNS cache"
}
# 2. Cerrar navegadores
Write-Host "[2] Cerrando navegadores..."
$browsers = "chrome","msedge","firefox"
foreach ($b in $browsers) {
Get-Process -Name $b -ErrorAction SilentlyContinue | Stop-Process -Force
}
# 3. Rutas de caché
$paths = @(
"$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache",
"$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\Cache",
"$env:LOCALAPPDATA\Mozilla\Firefox\Profiles"
)
# 4. Limpiar caché general (rápido)
Write-Host "[3] Limpiando caché de navegadores..."
foreach ($path in $paths) {
if (Test-Path $path) {
try {
Remove-Item "$path\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "Cache limpiado en $path"
} catch {
Write-Warning "No se pudo limpiar $path"
}
}
}
# 5. Limpieza selectiva (best effort)
Write-Host "[4] Buscando archivos relacionados con el dominio..."
foreach ($path in $paths) {
if (Test-Path $path) {
Get-ChildItem -Path $path -Recurse -ErrorAction SilentlyContinue |
ForEach-Object {
try {
$content = Get-Content $_.FullName -ErrorAction SilentlyContinue
if ($content -match $Domain) {
Remove-Item $_.FullName -Force -ErrorAction SilentlyContinue
Write-Host "Eliminado: $($_.FullName)"
}
} catch {}
}
}
}
# 6. Limpiar TEMP
Write-Host "[5] Limpiando archivos temporales..."
Remove-Item "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
# 7. Opcional: bloquear dominio
if ($BlockDomain) {
Write-Host "[6] Bloqueando dominio en hosts..."
$hostsPath = "C:\Windows\System32\drivers\etc\hosts"
$entry = "0.0.0.0 $Domain"
if (-not (Select-String -Path $hostsPath -Pattern $Domain -Quiet)) {
Add-Content -Path $hostsPath -Value "`n$entry"
Write-Host "Dominio bloqueado"
} else {
Write-Host "El dominio ya estaba bloqueado"
}
}
Write-Host "=== Proceso completado ===" -ForegroundColor Green
# Configurador DNS Anti-Malware - PowerShell (Auto-Renew)
Write-Host "================================================" -ForegroundColor Green
Write-Host "Configura DNS para bloquear malware, ads y spam." -ForegroundColor Yellow
Write-Host "Ejecutándose como ADMINISTRADOR - Auto-renew..."
Write-Host "================================================" -ForegroundColor Green
Write-Host "Limpiando cache DNS..." -ForegroundColor Cyan
ipconfig /flushdns
Write-Host "`nSelecciona (1-3 o 0 para revertir):" -ForegroundColor Cyan
Write-Host "1. Cloudflare Malware (1.1.1.3, 1.0.0.3)"
Write-Host "2. Quad9 (9.9.9.9, 149.112.112.112)"
Write-Host "3. AdGuard (94.140.14.14, 94.140.15.15)"
Write-Host "0. REVERTIR a DHCP automático"
$choice = Read-Host "Opci├│n"
switch ($choice) {
"1" { $dns = @("1.1.1.3", "1.0.0.3"); Write-Host "Γ£ô Configurando Cloudflare..." -ForegroundColor Green }
"2" { $dns = @("9.9.9.9", "149.112.112.112"); Write-Host "Γ£ô Configurando Quad9..." -ForegroundColor Green }
"3" { $dns = @("94.140.14.14", "94.140.15.15"); Write-Host "Γ£ô Configurando AdGuard..." -ForegroundColor Green }
"0" { $dns = $null; Write-Host "Γ£ô Revirtiendo a DHCP..." -ForegroundColor Yellow }
default { Write-Host "✗ Opción inválida."; Read-Host "Presiona Enter para salir"; exit }
}
$interfaces = Get-NetAdapter | Where-Object { $_.Status -eq "Up" }
Write-Host "`nAplicando a $($interfaces.Count) interfaces activas..." -ForegroundColor Cyan
foreach ($adapter in $interfaces) {
Write-Host " → $($adapter.InterfaceAlias)" -ForegroundColor White
if ($dns) {
Set-DnsClientServerAddress -InterfaceAlias $adapter.InterfaceAlias -ServerAddresses $dns -ErrorAction SilentlyContinue
} else {
Set-DnsClientServerAddress -InterfaceAlias $adapter.InterfaceAlias -ResetServerAddresses -ErrorAction SilentlyContinue
}
}
Write-Host "`n🔄 Renovando configuración de red automáticamente..." -ForegroundColor Yellow
ipconfig /renew * | Out-Null
ipconfig /flushdns
Write-Host "`n================================================" -ForegroundColor Green
Write-Host "✅ ¡LISTO! DNS configurado y renovado automáticamente." -ForegroundColor Green
Write-Host " Verifica con: Get-DnsClientServerAddress" -ForegroundColor Cyan
Write-Host "================================================" -ForegroundColor Green
Read-Host "Presiona Enter para salir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment