linux 不同接口上的Speedtest-cli

bbuxkriu  于 2023-06-29  发布在  Linux
关注(0)|答案(2)|浏览(146)

我有eth0,eth 1和wlan 0连接到我的树莓派。我想测量不同接口的互联网速度,在这种情况下-eth 1。它在eth0(192.168.1.21)上工作得很好,但是如果我尝试使用不同的接口,在本例中是eth 1(192.168.8.100),我会得到一个错误。
我阅读了Speedtest python API文档,大部分代码都是从那里复制的。我也试着在StackOverflow上发帖之前搜索。

source = "192.168.8.100" #eth1
s = speedtest.Speedtest(source_address=source)
s.get_servers()
s.get_best_server()
s.download()
s.upload()
res = s.results.dict()
download = res["download"]
upload = res["upload"]
ping = round(res["ping"])
print(download, upload, ping)

编辑:这是错误:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.8/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.8/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/post_test2.py", line 11, in home
    s = speedtest.Speedtest(source_address=source)
  File "/usr/lib/python3/dist-packages/speedtest.py", line 1091, in __init__
    self.get_config()
  File "/usr/lib/python3/dist-packages/speedtest.py", line 1123, in get_config
    raise ConfigRetrievalError(e)
speedtest.ConfigRetrievalError: <urlopen error timed out>
0ve6wy6x

0ve6wy6x1#

我是speedtest-cli的新手,这篇文章回答了我关于如何使用不同接口的问题。所以,谢谢你:-)
这是一个猜测,但你的问题可能是由于网络路由。是否可以通过以下两个接口ping外部主机:

ping -I eth0 google.com
ping -I eth1 google.com

如果eth 1超时,那么您可能需要更新网络路由条目。

ip route
cbeh67ev

cbeh67ev2#

有人在这上面发现什么了吗?只有当VPN打开并且我想测试另一个连接时,我才会遇到此问题
speedtest --source 192.168.1.2 Retrieving speedtest.net> configuration...无法检索速度测试配置错误:
如果VPN关闭,一切正常...

相关问题