topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 1:08 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Ping with latency alarm?  (Read 6775 times)

timmy2

  • Supporting Member
  • Joined in 2008
  • **
  • default avatar
  • Posts: 28
    • View Profile
    • Donate to Member
Ping with latency alarm?
« on: May 14, 2021, 08:49 PM »
I am looking for a program that can ping an address every 2 seconds and play a sound when the return time exceeds a certain value. It needs to display a timestamp and return time for every ping so I can capture this output to a text file, which I'll then import into Excel.

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,540
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Ping with latency alarm?
« Reply #1 on: May 15, 2021, 03:16 AM »
The simplest way to do this might be to write/use a PowerShell script.
You could set the alarm value as a variable for testing with an IF statement, or just dump all the pin responses into (say) an Excel spreadsheet or Access database for analysis.
Refer for example: https://www.checkyou...-powershell-mvphour/

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Ping with latency alarm?
« Reply #2 on: May 15, 2021, 02:13 PM »
Seems like a good idea for a coding snack.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,641
    • View Profile
    • Donate to Member
Re: Ping with latency alarm?
« Reply #3 on: May 17, 2021, 07:31 AM »
Someone will come up with something fancier but it gave me something to do  :)

It's only requirement is PowerShell 7 or higher, (I no longer use earlier versions).

Doesn't write to console, just directly to the output file.

Code: PowerShell [Select]
  1. <#
  2.   pinger.ps1
  3.  
  4.   Run: pwsh -F path\to\pinger.ps1
  5. #>
  6.  
  7. $ip = "8.8.8.8"       # IP/site to ping
  8. $file = "R:\ping.csv" # Output file, (will be output as CSV)
  9. $maxlag = 40          # Latency above which to go beep
  10.  
  11. # If it ain't PowerShell 7+ we don't want to know about it.
  12. if ($PSVersionTable.PSVersion.Major -lt 7) {
  13.   "Requires PowerShell 7" | Out-Host
  14.   Start-Sleep 10
  15. } else {
  16.   While ($true) {  # Loop-de-loop
  17.     # Ping a site once and select latency
  18.     $lag = (Test-Connection -ComputerName $ip -Count 1 -Ping -IPv4 -DontFragment | Select-Object Latency)
  19.     # Format file output and append latest to file (date time,ip,latency,exceeds max)
  20.     "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss'),$($ip),$($lag.Latency),$($lag.Latency -gt $maxlag)" | Out-File $file -Append
  21.     # If latency is above maximum allowed value ...
  22.     if ($lag.Latency -gt $maxlag) {
  23.       # Go beep
  24.       [console]::beep(1000,500)
  25.     }
  26.     # Sleep, restful sleep ... for all of 2 seconds >:|
  27.     Start-Sleep -Seconds 2
  28.   }
  29. }


File output is in CSV format:
Code: Text [Select]
  1. 2021/05/17 22:22:35,8.8.8.8,6,False
  2. 2021/05/17 22:22:37,8.8.8.8,17,False
  3. 2021/05/17 22:22:39,8.8.8.8,41,True
  4. 2021/05/17 22:22:42,8.8.8.8,32,False
  5. 2021/05/17 22:22:44,8.8.8.8,32,False
  6. 2021/05/17 22:22:46,8.8.8.8,41,True
  7. 2021/05/17 22:22:48,8.8.8.8,33,False
  8. 2021/05/17 22:22:51,8.8.8.8,44,True
  9. 2021/05/17 22:22:53,8.8.8.8,43,True

GrumpyCoder

  • Supporting Member
  • Joined in 2015
  • **
  • Posts: 27
    • View Profile
    • https://grumpycoder.win/
    • Donate to Member
Re: Ping with latency alarm?
« Reply #4 on: December 15, 2022, 11:28 AM »
I didn't realize how old this thread is before I started working on a solution. In any case, it's already done, so here it is anyway.
I believe this should do what you wanted, but do note that I whipped it up in a couple of hours, so it's definitely not perfect.
PS: The "csv" file is saved right next to the executable.

Capture.PNGPing with latency alarm?

hamradio

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 825
  • Amateur Radio Guy
    • View Profile
    • HamRadioUSA.net
    • Read more about this member.
    • Donate to Member
Re: Ping with latency alarm?
« Reply #5 on: December 28, 2022, 12:56 PM »
I didn't realize how old this thread is before I started working on a solution. In any case, it's already done, so here it is anyway.
I believe this should do what you wanted, but do note that I whipped it up in a couple of hours, so it's definitely not perfect.
PS: The "csv" file is saved right next to the executable.

[ Invalid Attachment ]

I am pretty sure this could be classified as a NANY App this year I believe for you.

GrumpyCoder

  • Supporting Member
  • Joined in 2015
  • **
  • Posts: 27
    • View Profile
    • https://grumpycoder.win/
    • Donate to Member
Re: Ping with latency alarm?
« Reply #6 on: December 28, 2022, 01:45 PM »
I am pretty sure this could be classified as a NANY App this year I believe for you.

I created a NANY entry for it, thanks for the suggestion.  :Thmbsup: