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

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

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

bprodoehl
Copy link

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.

@XLPI
Copy link

XLPI commented Jan 22, 2021

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

@fox091
Copy link

fox091 commented Mar 30, 2021

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.

@mavoga
Copy link

mavoga commented Sep 15, 2021

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).

@ghost
Copy link

ghost commented Oct 11, 2021

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.

@mavoga
Copy link

mavoga commented Oct 12, 2021

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.

@ghost
Copy link

ghost commented Oct 12, 2021

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

@dlenski
Copy link

dlenski commented Dec 30, 2021

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.:

Adapting speedtest.py to use the JSON server list instead of the XML server lists is extremely simple. See dlenski@45f0aff?w=1

@nkgiovannivl
Copy link

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!

@Overv
Copy link

Overv commented Feb 5, 2022

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.

@loonlim
Copy link

loonlim commented Feb 16, 2022

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

@lostcontrol
Copy link

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 = {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants