Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for JSON output #126

Open
janpelikan opened this issue Apr 5, 2023 · 2 comments
Open

Add option for JSON output #126

janpelikan opened this issue Apr 5, 2023 · 2 comments
Labels

Comments

@janpelikan
Copy link

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)'
@Killeroo
Copy link
Owner

Killeroo commented Apr 7, 2023

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?

@janpelikan
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Archived in project
Development

No branches or pull requests

2 participants