PowerPing icon indicating copy to clipboard operation
PowerPing copied to clipboard

Add option for JSON output

Open janpelikan opened this issue 1 year ago • 2 comments

In some cases, support for JSON output could be very useful. The JSON data structure is very well supported across almost all programming and scripting languages.

Please consider adding this feature to the next release.

Thanks.

Example:

Standard output

powerping 127.0.0.1

Pinging 127.0.0.1 with 35 bytes of data [Type=8 Code=0] [TTL=255]:
Reply from: 127.0.0.1:0 seq=1 bytes=63 type=ECHO REPLY time=1,2ms
Reply from: 127.0.0.1:0 seq=2 bytes=63 type=ECHO REPLY time=0,0ms
Reply from: 127.0.0.1:0 seq=3 bytes=63 type=ECHO REPLY time=0,0ms
Reply from: 127.0.0.1:0 seq=4 bytes=63 type=ECHO REPLY time=0,0ms

--- Stats for 127.0.0.1 ---
   General: Sent [ 4 ], Recieved [ 4 ], Lost [ 0 ] (0% loss)
     Times: Min [ 0,0ms ], Max [ 1,2ms ], Avg [ 0,3ms ]
     Types: Good [ 4 ], Errors [ 0 ], Unknown [ 0 ]
Started at: 05.04.2023 10:46:03 (local time)
   Runtime: 00:00:03.3

Example output in JSON format

powerping 127.0.0.1 --json

{
    "destination":"127.0.0.1",
    "packet_transmit":4,
    "packet_receive":4,
    "packet_loss_rate":0.0,
    "packet_loss_count":0,
    "rtt_min":0.0,
    "rtt_avg":0.3,
    "rtt_max":1.2,
    "runtime":"00:00:03.3",
    "ts":"05.04.2023 10:46:03 UTC+2"
}

Ouput can be parsed variously.

Parsed via PowerShell

powerping 127.0.0.1 --json | ConvertFrom-Json | Where-Object "rtt_avg" -GT "0.2"

destination       : 127.0.0.1
packet_transmit   : 4
packet_receive    : 4
packet_loss_rate  : 0,0
packet_loss_count : 0
rtt_min           : 0,0
rtt_avg           : 0,3
rtt_max           : 1,2
runtime           : 00:00:03.3
ts                : 05.04.2023 10:46:03 UTC+2

Or via jq

powerping 127.0.0.1 --json | jq '. | select(.rtt_avg > 0.2)'

janpelikan avatar Apr 05 '23 09:04 janpelikan

Thank you for your suggestion, I like the idea. I've added it to the feature list for the next release. So I assume there would be no output while PowerPing is running? Only when it finishes? So the json just represents the ping results?

Killeroo avatar Apr 07 '23 09:04 Killeroo

Well, it depends on the specific case. I believe that the JSON output can be used even in --infinite mode.

Example use case:

powerping.exe 127.0.0.1 -t | Tee-Object -FilePath C:\ping.txt -Append

With a JSON structure, it would be very easy and efficient to further process and parse the data.

But the JSON output after the command is complete will be awesome as well. Thanks a lot.

janpelikan avatar Apr 11 '23 19:04 janpelikan