sivel/speedtest-cli — pull request #28 by mcardillo55 (2013-08-16 05:32:34+00:00)
Title: perform ICMP pings on posix systems

The script was regularly returning 600ms+ pings, when the Speedtest site gives me ~20ms. I suspect this to be due to the current time module 'stopwatch' scheme. It's possible that the times may scale, and the fastest server may remain the same, but who knows how much of the overhead is due to Python and how much is due to the network.

ICMP sockets cannot be created without root access, so the simplest implementation of a true ICMP ping that I found is to just run it in a system shell. I've tested this on Linux (Debian) and Mac (10.8.4), as well as Python 2.4, 2.7 and 3.3. I would have done the Windows implementation too if I had easy access to a machine.

This change has brought my fastest ping down from 694ms to 21ms.