Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Created April 23, 2025 13:36
Show Gist options
  • Save zulhfreelancer/2a587cdff3bf2cc7743110e15a2c90d2 to your computer and use it in GitHub Desktop.
Save zulhfreelancer/2a587cdff3bf2cc7743110e15a2c90d2 to your computer and use it in GitHub Desktop.

Revisions

  1. zulhfreelancer created this gist Apr 23, 2025.
    23 changes: 23 additions & 0 deletions ping-time-loop.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    This PowerShell script will continuously prints the current time and pings an IP address.

    It will run in a loop until you press `Ctrl+C` to stop it.

    ```powershell
    # Replace <IP> with target host IP address
    try {
    while ($true) {
    $timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
    $pingResult = ping <IP> -n 1
    if ($pingResult -match "Reply from") {
    Write-Host "$timestamp - Host is up"
    } else {
    Write-Host "$timestamp - Host is down"
    }
    Start-Sleep -Seconds 1
    }
    } catch {
    Write-Host "Script interrupted."
    }
    ```