PYTHON

Cara Cek Kecepatan Internet Pada Python

Pada artikel ini saya akan membuat sebuah program python program yang saya buat di sini untuk mengecek internet sesuai judul artikel pastikan kamu sudah menginstall library bernama speedtest-cli cara install nya cukup mudah kamu masuk ke terminal kamu dan lihat cara install nya di bawah ini :

pip install speedtest-cli

Setelah menginstal paket di atas, kamu dapat memeriksa apakah paket tersebut diinstal dengan benar atau tidak dengan melakukan pemeriksaan versi. Versi paket dapat diperiksa menggunakan perintah berikut :

speedtest-cli --version

Dan hasil bisa di lihat di bawah ini :

C:\Users\galihap>speedtest-cli --version
speedtest-cli 2.1.3
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:13:28) [MSC v.1928 32 bit (Intel)]

Speedtest-cli adalah modul yang digunakan dalam antarmuka baris perintah untuk menguji bandwidth internet menggunakan speedtest.net. Untuk mendapatkan kecepatan dalam megabit, ketik perintah di bawah ini di terminal :

speedtest-cli

Hasil tersebut bisa di lihat di bawah ini :

C:\Users\galihap>speedtest-cli
Retrieving speedtest.net configuration...
Testing from Smartfren (114.79.18.223)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by PT Internet Mulia Untuk Negeri (Semarang) [2.99 km]: 82.768 ms
Testing download speed................................................................................
Download: 6.56 Mbit/s
Testing upload speed......................................................................................................
Upload: 6.56 Mbit/s

Perintah di atas memberikan hasil tes kecepatan dalam Megabit. Untuk mendapatkan hasil dalam Bytes kita dapat menggunakan perintah berikut :

speedtest-cli --bytes

Hasil bisa di lihat di bawah ini :

C:\Users\galihap>speedtest-cli --bytes
Retrieving speedtest.net configuration...
Testing from Smartfren (114.79.18.223)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by PT Grahamedia Informasi (Salatiga) [38.71 km]: 73.091 ms
Testing download speed................................................................................
Download: 0.46 Mbyte/s
Testing upload speed......................................................................................................
Upload: 0.71 Mbyte/s

Versi di atas dari hasil tes kecepatan kamu juga dapat diambil menggunakan modul ini. Untuk melakukan hal yang sama ketik perintah di bawah ini di terminal :

speedtest-cli --share

Hasil :

C:\Users\galihap>speedtest-cli --share
Retrieving speedtest.net configuration...
Testing from Smartfren (114.79.18.223)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by PT. Adau Putra Network (Kendal) [25.09 km]: 74.1 ms
Testing download speed................................................................................
Download: 6.42 Mbit/s
Testing upload speed......................................................................................................
Upload: 10.14 Mbit/s
Share results: http://www.speedtest.net/result/12726629714.png

Ini mengembalikan tautan yang dapat kita kunjungi di browser kita dan melihat representasi grafis dari berbagai jenis kecepatan internet kita.

Untuk mencetak versi hasil tes kecepatan yang lebih sederhana yang hanya berisi hasil Ping, Unduh dan Unggah alih-alih keluaran terperinci :

speedtest-cli --simple

Hasil bisa di lihat di bawah ini :

C:\Users\galihap>speedtest-cli --simple
Ping: 73.861 ms
Download: 6.80 Mbit/s
Upload: 6.49 Mbit/s

Saatnya Membuat Program Python Untuk Cek Internet

Kamu cukup copy dan paste kode python di bawah ini :

import speedtest

spd = speedtest.Speedtest()
print("""
kamu mau ngetes apa?
1. download speed
2. upload speed
3. ping
""")

user_option = int(input('masukkan nomor : '))

if user_option == 1:
    print(spd.download())
elif user_option == 2:
    print(spd.upload())
elif user_option == 3:
    servernames = []
    spd.get_servers(servernames)
    print(spd.results.ping)
else:
    exit(0)

Hasil bisa di lihat di bawah ini satu persatu :

C:\Users\galihap\Documents>main.py

kamu mau ngetes apa?
1. download speed
2. upload speed
3. ping

masukkan nomor : 1
4249991.874809486

C:\Users\galihap\Documents>main.py

kamu mau ngetes apa?
1. download speed
2. upload speed
3. ping

masukkan nomor : 2
1396895.8917594803

C:\Users\galihap\Documents>main.py

kamu mau ngetes apa?
1. download speed
2. upload speed
3. ping

masukkan nomor : 3
0

Untuk mendapatkan daftar semua opsi yang tersedia, ketik perintah di bawah ini di terminal :

speedtest-cli -h

Hasil :

C:\Users\galihap\Documents>speedtest-cli -h
usage: speedtest-cli [-h] [--no-download] [--no-upload] [--single] [--bytes] [--share] [--simple] [--csv]
                     [--csv-delimiter CSV_DELIMITER] [--csv-header] [--json] [--list] [--server SERVER]
                     [--exclude EXCLUDE] [--mini MINI] [--source SOURCE] [--timeout TIMEOUT] [--secure]
                     [--no-pre-allocate] [--version]

Command line interface for testing internet bandwidth using speedtest.net.
-------------------------------------------------------------------------- https://github.com/sivel/speedtest-cli

optional arguments:
  -h, --help            show this help message and exit
  --no-download         Do not perform download test
  --no-upload           Do not perform upload test
  --single              Only use a single connection instead of multiple. This simulates a typical file transfer.
  --bytes               Display values in bytes instead of bits. Does not affect the image generated by --share, nor
                        output from --json or --csv
  --share               Generate and provide a URL to the speedtest.net share results image, not displayed with --csv
  --simple              Suppress verbose output, only show basic information
  --csv                 Suppress verbose output, only show basic information in CSV format. Speeds listed in bit/s and
                        not affected by --bytes
  --csv-delimiter CSV_DELIMITER
                        Single character delimiter to use in CSV output. Default ","
  --csv-header          Print CSV headers
  --json                Suppress verbose output, only show basic information in JSON format. Speeds listed in bit/s and
                        not affected by --bytes
  --list                Display a list of speedtest.net servers sorted by distance
  --server SERVER       Specify a server ID to test against. Can be supplied multiple times
  --exclude EXCLUDE     Exclude a server from selection. Can be supplied multiple times
  --mini MINI           URL of the Speedtest Mini server
  --source SOURCE       Source IP address to bind to
  --timeout TIMEOUT     HTTP timeout in seconds. Default 10
  --secure              Use HTTPS instead of HTTP when communicating with speedtest.net operated servers
  --no-pre-allocate     Do not pre allocate upload data. Pre allocation is enabled by default to improve upload
                        performance. To support systems with insufficient memory, use this option to avoid a
                        MemoryError
  --version             Show the version number and exit

speedtest-cli --help

C:\Users\galihap\Documents>speedtest-cli --help
usage: speedtest-cli [-h] [--no-download] [--no-upload] [--single] [--bytes] [--share] [--simple] [--csv] [--csv-delimiter CSV_DELIMITER] [--csv-header] [--json]
                     [--list] [--server SERVER] [--exclude EXCLUDE] [--mini MINI] [--source SOURCE] [--timeout TIMEOUT] [--secure] [--no-pre-allocate] [--version]

Command line interface for testing internet bandwidth using speedtest.net. --------------------------------------------------------------------------
https://github.com/sivel/speedtest-cli

optional arguments:
  -h, --help            show this help message and exit
  --no-download         Do not perform download test
  --no-upload           Do not perform upload test
  --single              Only use a single connection instead of multiple. This simulates a typical file transfer.
  --bytes               Display values in bytes instead of bits. Does not affect the image generated by --share, nor output from --json or --csv
  --share               Generate and provide a URL to the speedtest.net share results image, not displayed with --csv
  --simple              Suppress verbose output, only show basic information
  --csv                 Suppress verbose output, only show basic information in CSV format. Speeds listed in bit/s and not affected by --bytes
  --csv-delimiter CSV_DELIMITER
                        Single character delimiter to use in CSV output. Default ","
  --csv-header          Print CSV headers
  --json                Suppress verbose output, only show basic information in JSON format. Speeds listed in bit/s and not affected by --bytes
  --list                Display a list of speedtest.net servers sorted by distance
  --server SERVER       Specify a server ID to test against. Can be supplied multiple times
  --exclude EXCLUDE     Exclude a server from selection. Can be supplied multiple times
  --mini MINI           URL of the Speedtest Mini server
  --source SOURCE       Source IP address to bind to
  --timeout TIMEOUT     HTTP timeout in seconds. Default 10
  --secure              Use HTTPS instead of HTTP when communicating with speedtest.net operated servers
  --no-pre-allocate     Do not pre allocate upload data. Pre allocation is enabled by default to improve upload performance. To support systems with insufficient
                        memory, use this option to avoid a MemoryError
  --version             Show the version number and exit

Penutup

Nah itulah yang bisa saya sampaikan bagaimana cara cek internet di python dan beberapa penjelasan mengenai library nya di atas. Semoga bermanfaat :D