Ping program in Java to determine the “network throughput”

I had to determine the “network throughput” from a server to another server. Idea is to use the ping command  to get the information. The ping can send the data multiple times and at the end of the process, give the average time it took to process.

The expected output is displayed below in blue color which has the average time and capture the number.

Below is the example.

C:\>ping www.yahoo.com -n 2 -l 210

Pinging any-fp.wa1.b.yahoo.com [67.195.160.76] with 210 bytes of data:

Reply from 67.195.160.76: bytes=210 time=56ms TTL=51
Reply from 67.195.160.76: bytes=210 time=78ms TTL=51

Ping statistics for 67.195.160.76:
Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:

Minimum = 56ms, Maximum = 78ms, Average = 67ms

Here is my pseudo code >>

– Run the program from the server. It is checking throughput to the server mentioned in args[1]
– Need 2 arguments 1) URI of the server  2) Interval 3) data packet to transfer in bytes
– Run a Ping command  args[0] -n args [1] -l args[2]
– Parse the results and get the average time taken
– Throughput (KB/s) is =  ( args[2] * 1000000 /(Avg))/1024
– Because avg is in ms; use 1024 to convert the Throughput to KB/sec

Source File: Ping.java
(Replace the “.java_.txt” extension to “.java” before using the file)

leave your comment