Last active
January 31, 2026 15:23
-
-
Save s-h-a-d-o-w/934c6ef2e05f3f3ba74f4f6c0b1bf94f to your computer and use it in GitHub Desktop.
Repeatedly checks whether a certain IP is reachable and shows a popup if it's not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ip = "..." | |
| Add-Type -AssemblyName System.Windows.Forms | |
| $ping = New-Object System.Net.NetworkInformation.Ping | |
| while ($true) { | |
| $failures = 0 | |
| for ($i = 0; $i -lt 15; $i++) { | |
| try { | |
| $result = $ping.Send($ip, 3000) # 3 second timeout | |
| if ($result.Status -ne 'Success') { $failures++ } | |
| } catch { | |
| $failures++ | |
| } | |
| Start-Sleep -Seconds 1 | |
| } | |
| if ($failures -eq 15) { # All 15 failed | |
| [System.Windows.Forms.MessageBox]::Show( | |
| "Device $ip is offline!", | |
| "Network Alert", | |
| [System.Windows.Forms.MessageBoxButtons]::OK, | |
| [System.Windows.Forms.MessageBoxIcon]::Warning | |
| ) | Out-Null | |
| } | |
| Start-Sleep -Seconds 5 | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't use
Test-Connection, it's highly unreliable.Also, for running this in the background with Task Scheduler, you'll need a second script: