Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing $targets = @( @{ Name = "Gateway"; Host = "192.168.1.1" }, @{ Name = "Internet"; Host = "1.1.1.1" } ) $logDir = "C:\RedLogs" New-Item -ItemType Directory -Force -Path $logDir | Out-Null $logFile = Join-Path $logDir ("monitor_red_" + (Get-Date -Format "yyyy-MM-dd") + ".log") $fails = @{ "Gateway" = 0 "Internet" = 0 } $alertShown = $false function Write-Log($msg) { $msg | Out-File -FilePath $logFile -Append -Encoding utf8 } function Play-GatewayAlert { [console]::beep(1400,300) Start-Sleep -Milliseconds 100 [console]::beep(1400,300) Start-Sleep -Milliseconds 100 [console]::beep(1400,700) } function Play-InternetAlert { [console]::beep(900,250) Start-Sleep -Milliseconds 100 [console]::beep(900,250) Start-Sleep -Milliseconds 100 [console]::beep(900,500) } function Show-AlertForm($title, $message) { $form = New-Object System.Windows.Forms.Form $form.Text = $title $form.Size = New-Object System.Drawing.Size(520,220) $form.StartPosition = "CenterScreen" $form.TopMost = $true $form.BackColor = [System.Drawing.Color]::FromArgb(180,0,0) $label = New-Object System.Windows.Forms.Label $label.Text = $message $label.ForeColor = [System.Drawing.Color]::White $label.Font = New-Object System.Drawing.Font("Segoe UI",16,[System.Drawing.FontStyle]::Bold) $label.AutoSize = $false $label.TextAlign = "MiddleCenter" $label.Dock = "Fill" $button = New-Object System.Windows.Forms.Button $button.Text = "Cerrar" $button.Width = 120 $button.Height = 36 $button.Top = 130 $button.Left = 190 $button.Add_Click({ $form.Close() }) $form.Controls.Add($label) $form.Controls.Add($button) $form.ShowDialog() | Out-Null } while ($true) { $ts = Get-Date -Format "yyyy-MM-dd HH:mm:ss" foreach ($t in $targets) { try { $r = Test-Connection -ComputerName $t.Host -Count 1 -ErrorAction Stop $ms = ($r | Select-Object -First 1).ResponseTime $fails[$t.Name] = 0 $status = "OK" if ($ms -ge 100) { $status = "ALTA_LATENCIA" } Write-Log "$ts | $($t.Name) | $($t.Host) | $status | ${ms}ms" } catch { $fails[$t.Name]++ Write-Log "$ts | $($t.Name) | $($t.Host) | FAIL | intento=$($fails[$t.Name])" if ($fails[$t.Name] -eq 3) { if ($t.Name -eq "Gateway") { Play-GatewayAlert Show-AlertForm "ALERTA DE RED LOCAL" "Fallo el gateway 192.168.1.1`nRevisar Peplink / switch / Deco" } elseif ($t.Name -eq "Internet") { Play-InternetAlert Show-AlertForm "ALERTA DE INTERNET" "Fallo 1.1.1.1`nRevisar WAN / ISP / ruteo" } } } } Start-Sleep -Seconds 1 }