Search code examples
javaswingbandwidth

Display my bandwidth connection


I need to display on my java frame my bandwith every X time, but i don't know how to do it, ping only gives me reachability but not bandwidth... I need to "download" something to get the speed but I don't know how... Thanks!


Solution

  • ping gives you enough details to calculate bandwidth

    for the below ping command

    > ping google.com
    

    output :

    Reply from 216.58.197.46: bytes=32 time=26ms TTL=56
    Reply from 216.58.197.46: bytes=32 time=25ms TTL=56
    Reply from 216.58.197.46: bytes=32 time=26ms TTL=56
    Reply from 216.58.197.46: bytes=32 time=25ms TTL=56
    
    Ping statistics for 216.58.197.46:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 25ms, Maximum = 26ms, Average = 25ms
    

    Average Time taken to transmit 32 bytes of data is 25ms

    Therefore

    bandwidth = (32/25) bytes/ms = ( 32*8 / 0.025 ) bps = 10240 bps = 10240 / 1024 kbps = 10 kbps

    Hope this is useful to you.