speedtest-cli icon indicating copy to clipboard operation
speedtest-cli copied to clipboard

Reorder speedtest servers URLs, preferring c.speedtest.net domain

Open bprodoehl opened this issue 5 years ago • 11 comments

There's a subtle difference in behavior between the c.speedtest.net and www.speedtest.net domains, with c.speedtest.net yielding a server list that is more relevant to the actual location that it is run from. This PR just reorders the four URLs that are used to fetch the server list, bumping the c.speedtest.net URLs to the top.

Both domains return 100 servers in the results, but if run from Perth, Australia, c.speedtest.net returns 100 servers centered around Perth (with 14 actually in Perth) and www.speedtest.net returns 100 servers centered around Sydney, with the nearest server over 1300 miles away. I have seen similar results in the US, as well.

bprodoehl avatar Dec 07 '20 21:12 bprodoehl

Hi guys. Is it possible now to get a list of servers of a specific country, for example USA when I'm using speed-test cli from Ukraine. It could be very useful feature. Now I have a choice to see servers of Ukraine's only

XLPI avatar Jan 22 '21 13:01 XLPI

I couldn't use any of my local servers by passing in their ids into get_servers(). I always got a no matched servers error. I noticed that the list I was pulling from was giving my local servers and speedtest-cli was not. Thankfully I stumbled upon this PR that fixes this exact problem.

I checked out this branch (thanks @bprodoehl !) and it works great. I can use any of my local servers now. Hope this will be merged to the main package soon.

fox091 avatar Mar 30 '21 05:03 fox091

By analyzing the official test webpage requests it seems JSON server list at https://www.speedtest.net/api/js/servers?engine=js&limit=10&https_functional=true is used instead of XML at www.speedtest.net/speedtest-servers(-static)?.php and c.speedtest.net/speedtest-servers(-static)?.php. The JSON list contains pretty accurate results, while XML (both servers) usually doesn't. A ping analysis is then performed on each server in order to determine which one has the least latency and to get further info (IP, capabilities).

mavoga avatar Sep 15 '21 13:09 mavoga

By analyzing the official test webpage requests it seems JSON server list at https://www.speedtest.net/api/js/servers?engine=js&limit=10&https_functional=true is used instead of XML at www.speedtest.net/speedtest-servers(-static)?.php and c.speedtest.net/speedtest-servers(-static)?.php. The JSON list contains pretty accurate results, while XML (both servers) usually doesn't. A ping analysis is then performed on each server in order to determine which one has the least latency and to get further info (IP, capabilities).

I followed @mavoga hint and replaced the XML lists by the JSON list: https://github.com/Kerybas/speedtest-cli

It works fine and returns a better server list (the old one wouldn't return any server from my city, despite having a couple).

However, I see download/upload results that are too far from the expected results, and from what I can see on the website. Not sure if it could be linked to the switch to JSON list, I have to pause the investigation for the moment.

ghost avatar Oct 11 '21 20:10 ghost

I followed @mavoga hint and replaced the XML lists by the JSON list: https://github.com/Kerybas/speedtest-cli

It works fine and returns a better server list (the old one wouldn't return any server from my city, despite having a couple).

However, I see download/upload results that are too far from the expected results, and from what I can see on the website. Not sure if it could be linked to the switch to JSON list, I have to pause the investigation for the moment.

Hi @Kerybas , now it works like a charm here in Rome and the outcome is just as expected both for the servers used and for the speed test results. Thanks! A further possible improvement would be to allow the server to be selected among more than 10 results (notice the limit=10 parameter in the request): this should be especially useful when listing available servers for later manual selection.

mavoga avatar Oct 12 '21 15:10 mavoga

@mavoga : re the number of servers, I notice that the API limits it at 20 but I forgot to change it in the code. :)

ghost avatar Oct 12 '21 16:10 ghost

Hi guys. Is it possible now to get a list of servers of a specific country, for example USA when I'm using speed-test cli from Ukraine. It could be very useful feature. Now I have a choice to see servers of Ukraine's only

Yes, basically.

The current Speedtest.net web interface users a JSON-based endpoint to list the available servers: https://www.speedtest.net/api/js/servers. This one can take a search parameter, e.g.:

  • https://www.speedtest.net/api/js/servers?search=United+States
  • https://www.speedtest.net/api/js/servers?search=Ukraine

Adapting speedtest.py to use the JSON server list instead of the XML server lists is extremely simple. See https://github.com/dlenski/speedtest-cli/commit/45f0affa25e6a85cf1e9e966e79b26482fe073e0?w=1

dlenski avatar Dec 30 '21 21:12 dlenski

Hi All,

I'm using to install:

pip install git+https://github.com/sivel/speedtest-cli.git

and, but my server list still using XML instead of JSON, need i to wait a official release? or change the url of my command installation to use another reppository? Thanks!

nkgiovannivl avatar Jan 19 '22 22:01 nkgiovannivl

I've also noticed that https://www.speedtest.net/speedtest-servers-static.php returns much less accurate results if you send the request with a user agent that looks like a script.

The difference can be observed when running these two commands:

# Less accurate
curl 'https://www.speedtest.net/speedtest-servers-static.php' -H 'User-Agent: curl'

# More accurate
curl 'https://www.speedtest.net/speedtest-servers-static.php' -H 'User-Agent: kurl'

This same difference is evident in speedtest-cli due to the default Python-like user agent. The JSON endpoint doesn't suffer from this problem.

Overv avatar Feb 05 '22 20:02 Overv

Hi , Is it possible test by my server connect to other servers of a specific country?

loonlim avatar Feb 16 '22 16:02 loonlim

Same issue here. I'm located in Switzerland but only get servers from France and Germany. If I change the order of the list of URL, it then works as expected, giving me servers in my country:

--- speedtest.py     2022-04-07 10:43:41.620741209 +0200
+++ speedtest.py     2022-04-07 10:59:18.743962835 +0200
@@ -1250,10 +1250,10 @@
                     )
 
         urls = [
-            '://www.speedtest.net/speedtest-servers-static.php',
-            'http://c.speedtest.net/speedtest-servers-static.php',
             '://www.speedtest.net/speedtest-servers.php',
             'http://c.speedtest.net/speedtest-servers.php',
+            '://www.speedtest.net/speedtest-servers-static.php',
+            'http://c.speedtest.net/speedtest-servers-static.php',
         ]
 
         headers = {}

lostcontrol avatar Apr 07 '22 09:04 lostcontrol