Python ใไฝฟ็จใใฆใคใณใฟใผใใใ้ๅบฆใใใงใใฏใใ้ใฎไธปใชๅ้กใฏใๆจๆบๅใใใๆนๆณใใชใใใจใงใใ ใใญใฐใฉใ ใ็ฐใชใใฐ็ตๆใ็ฐใชใใพใใXNUMX ใคใฎใใญใฐใฉใ ใงๆฅ็ถใ้ซ้ใงใใใจ่กจ็คบใใใใจใใฆใใๅฎ้ใซใฏใใใงใฏใชใๅฏ่ฝๆงใใใใพใใ
import speedtest import os import time def test_speed(): s = speedtest.Speedtest() s.get_best_server() s.download() s.upload() return s.results.dict()['download'] / 8000000, s.results.dict()['upload'] / 8000000, s.results.dict()['ping'] def main(): while True: download, upload, ping = test_speed() print('Download: {:0.2f} MbpstUpload: {:0.2f} MbpstPing: {} ms'.format(download, upload, ping)) time.sleep(5) if __name__ == '__main__': main()
ๆๅใฎ XNUMX ่กใฏใspeedtestใosใใใใณ time ใขใธใฅใผใซใใคใณใใผใใใพใใ
ๆฌกใฎ่กใงใฏใtest_speed() ใจใใๅๅใฎ้ขๆฐใๅฎ็พฉใใฆใใพใใ ใใฎ้ขๆฐใฏใspeedtest ใขใธใฅใผใซใไฝฟ็จใใฆใคใณใฟใผใใใๆฅ็ถใฎ้ๅบฆใใในใใใ็ตๆใ่ฟใใพใใ
ๆฌกใฎ่กใงใฏใmain() ใจใใๅๅใฎ้ขๆฐใๅฎ็พฉใใฆใใพใใ ใใฎ้ขๆฐใฏ test_speed() ้ขๆฐใๅผใณๅบใใ็ตๆใๅบๅใใพใใ ใใฎๅพใ็นฐใ่ฟใๅใซ 5 ็ง้ในใชใผใใใพใใ
ๆๅพใซใใใฎใใกใคใซใ (ใขใธใฅใผใซใจใใฆใคใณใใผใใใใใฎใงใฏใชใ) ในใฏใชใใใจใใฆๅฎ่กใใใๅ ดๅใmain() ้ขๆฐใๅผใณๅบใใใพใใ
ใคใณใฟใผใใใ้ๅบฆใจใฏ
Python ใงใฎใคใณใฟใผใใใใฎ้ๅบฆใฏใXNUMX ็งใใใใฎใใคใๆฐใงๆธฌๅฎใงใใพใใ
ใคใณใฟใผใใใ้ๅบฆใตใผใใน
Python ใงใคใณใฟใผใใใๆฅ็ถใฎ้ๅบฆใๆธฌๅฎใใใซใฏใใใใคใใฎๆนๆณใใใใพใใ ๆใ็ฐกๅใชๆนๆณใฏใ็ตใฟ่พผใฟ้ขๆฐ time ใไฝฟ็จใใใใจใงใใ time() ใฏใ็พๅจใฎๆๅปใ็งๅไฝใงๅบๅใใพใใ
ใคใณใฟใผใใใๆฅ็ถใฎ้ๅบฆใๆธฌๅฎใใ XNUMX ใค็ฎใฎๆนๆณใฏใnetstat ใณใใณใใไฝฟ็จใใใใจใงใใ netstat ใฏใใในใฆใฎใขใฏใใฃใใชใใใใฏใผใฏๆฅ็ถใจใใฎในใใผใฟในใ่กจ็คบใใพใใ ็นๅฎใฎใใใใฏใผใฏๆฅ็ถใฎ้ๅบฆใซ้ขใใๆ ๅ ฑใๅๅพใใใซใฏใ-i ใชใใทใงใณใไฝฟ็จใใพใใ
$ netstat -i | grep โ:80โ ใขใฏใใฃใใชใคใณใฟใผใใใๆฅ็ถ (ใตใผใใผใจใฏใฉใคใขใณใ) Proto Recv-Q Send-Q ใญใผใซใซ ใขใใฌใน ๅค้จใขใใฌใน ็ถๆ PID/ใใญใฐใฉใ ๅ tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 548/sshd tcp6 0 0 : ::80 :::* LISTEN 672/docker tcp6 0 1 ::1:80 :::* LISTEN 672/docker