A lightweight PowerShell tool for monitoring network connectivity that only logs when something changes. It pings configured targets on a schedule and records state transitions with timestamps, helping diagnose network issues without generating excessive logs.
- Pings a configurable list of IP addresses or hostnames on a regular interval.
- Retries each target up to
Counttimes before marking it unreachable, filtering out transient network glitches. - Logs only on state changes (Unknown → Accessible/Inaccessible, or Accessible ↔ Inaccessible).
- Records the duration of each state (formatted as hh:mm:ss) to track outage lengths.
- Writes change-only logs to
log/WindowsPinger.log. - Integrates with SvcWatchDog to run as a Windows service, enabling deployment on client machines for passive monitoring.
- Edit the configuration at the top of
scripts/WindowsPinger.ps1:
$pingEntries = @(
@{ Name = "Google DNS"; Address = "8.8.8.8"; Timeout = 1000; Count = 3; State = "Unknown"; LastChange = $null },
@{ Name = "Cloudflare DNS"; Address = "1.1.1.1"; Timeout = 1000; Count = 3; State = "Unknown"; LastChange = $null },
@{ Name = "Local Gateway"; Address = "192.168.1.1"; Timeout = 500; Count = 6; State = "Unknown"; LastChange = $null },
)Configuration parameters:
Name: Descriptive label for log entries.Address: IP address or hostname to ping.Timeout: Timeout per ping attempt in milliseconds.Count: Maximum ping attempts per cycle; stops early on first success.StateandLastChange: Leave as shown; managed internally by the script.
- Set the interval between ping cycles:
$interval = 10 # seconds- Run the script:
powershell.exe -ExecutionPolicy Bypass -File .\scripts\WindowsPinger.ps1- Check
log/WindowsPinger.logfor change-only entries:
12/06/2025 10:15:23: [Google DNS] 8.8.8.8 is Accessible
12/06/2025 10:47:11: [UbuntuDev] 10.255.254.150 is now Inaccessible (was Accessible for 00:12:34)
12/06/2025 10:50:21: [UbuntuDev] 10.255.254.150 is now Accessible (was Inaccessible for 00:03:10)
WindowsPinger is a standalone PowerShell script, but running it as a Windows service is crucial for deployment scenarios. IT administrators can install it on client machines as a background service, allowing passive network monitoring without user interaction. Later, they can review the logs to diagnose connectivity issues.
This integration is enabled by SvcWatchDog, a lightweight Windows service wrapper that can run any console application as a service. SvcWatchDog handles service lifecycle management, automatic restarts, and graceful shutdown.
Option 1: Using the official release (recommended)
Download the pre-packaged release from the WindowsPinger Releases section. The release already includes SvcWatchDog (renamed to WindowsPingerService.exe) and a sample configuration file (WindowsPingerService.json) in the service directory. You can skip to the Installation section below.
Option 2: Manual setup
If you're building from source or customizing the setup:
- Download or build SvcWatchDog.exe from the SvcWatchDog releases.
- Rename it to
WindowsPingerService.exe(or your preferred service name). - Place
WindowsPingerService.exein theservicedirectory of this project. - Create a configuration file named
WindowsPingerService.jsonin the sameservicedirectory.
Example WindowsPingerService.json:
{
"log": {
"minConsoleLevel": 99,
"minFileLevel": 0,
"filePath": "log\\SvcWatchDog.log",
"maxFileSize": 10000000,
"maxOldFiles": 3,
"maxWriteDelay": 500
},
"svcWatchDog": {
"workDir": "..",
"args": [
"powershell.exe",
"-ExecutionPolicy",
"Unrestricted",
"-File",
"scripts\\WindowsPinger.ps1"
],
"usePath": true,
"autoStart": true,
"restartDelay": 2000,
"shutdownTime": 3000,
"watchdogTimeout": 30000
}
}Key parameters:
workDir: Set to".."so paths are relative to the project root (parent of theservicefolder).args: Command line to launch PowerShell and executeWindowsPinger.ps1.autoStart: Set totrueto start the service automatically on system boot.watchdogTimeout: UDP ping timeout in milliseconds. The script sends heartbeats to SvcWatchDog; if no heartbeat is received within this timeout, the service is restarted. Set this to at least twice your ping$interval(e.g., 30000 ms for a 10-second interval). Set to-1to disable watchdog monitoring.
Navigate to the project directory and run:
# Install the service
service\WindowsPingerService.exe -i
# Start the service
net start WindowsPingerService
# Stop the service
net stop WindowsPingerService
# Uninstall the service
service\WindowsPingerService.exe -uOnce installed, the service files (WindowsPingerService.exe and WindowsPingerService.json) must remain in the service directory. Moving them will break the service.
SvcWatchDog integrates with the Windows service system and manages the WindowsPinger script:
- Starts the script when the service starts.
- Monitors the script's health via optional UDP heartbeats.
- Automatically restarts the script if it crashes or becomes unresponsive.
- Signals graceful shutdown via a Win32 event (the
SHUTDOWN_EVENTenvironment variable).
The script already includes integration code to:
- Send UDP heartbeats to SvcWatchDog (using
WATCHDOG_PORTandWATCHDOG_SECRETenvironment variables). - Monitor the
SHUTDOWN_EVENTfor graceful termination.
For most deployments, the example configuration above is sufficient. Refer to the SvcWatchDog documentation for advanced configuration options like email notifications, log rotation, and encrypted credentials.
- Network diagnostics: Identify when and for how long network resources become unavailable.
- Passive monitoring: Deploy as a service on client machines to collect connectivity data without user involvement.
- Troubleshooting intermittent issues: The retry mechanism filters out one-off glitches while capturing genuine outages.
- Historical analysis: Change-only logging keeps files small, making it easy to review connectivity patterns over weeks or months.
- Windows with PowerShell (tested with Windows PowerShell 5.1).
- Network access to the configured targets.
- (Optional) SvcWatchDog for running as a Windows service.
- Increase
Countif your network is noisy or experiences frequent transient packet loss. This prevents false alarms. - Decrease
Countfor faster detection of genuine outages. - Adjust
Timeoutbased on expected network latency. Lower values detect issues faster but may trigger false positives on slow links. - Total wait time per target is roughly
Count * Timeoutmilliseconds when the target is unreachable. - Ping interval (
$interval) should be shorter than the SvcWatchDogwatchdogTimeoutto ensure heartbeats arrive on time.