Ping

Linux ping 命令獲取 rtt

  • November 28, 2020

我是 Linux 新手,我正在嘗試 ping 伺服器,我想知道如何獲取或計算 Linux 的往返時間 (RTT) 的中位數?

Ping 或 Packet Internet Groper 是一種網路管理實用程序,用於檢查 IP 網路上源和目標電腦/設備之間的連接狀態。它還可以幫助您評估從網路發送和接收響應所需的時間。

$ ping -c 5 127.0.0.1

往返時間 (RTT)是發送信號所需的時間長度加上接收該信號的確認所需的時間長度。因此,該時間包括兩個信號點之間的傳播時間。在 Internet 上,最終使用者可以通過 ping 該地址來確定與 IP(**Internet 協議)地址之間的 RTT。**結果取決於各種因素:-

1. The data rate transfer of the source’s internet connection.
2. The nature of transmission medium.
3. The physical distance between source and destination.
4. The number of nodes between source and destination.
5. The amount of traffic on the LAN(Local Area Network) to which end user is connected.
6. The number of other requests being handled by intermediate nodes and the remote server.
7. The speed with which intermediate node and the remote server function.
8.The presence of Interference in the circuit.
# This program is used to calculate RTT 

import time 
import requests 

# Function to calculate the RTT 
def RTT(url): 

   # time period when the signal is sent 
   t1 = time.time() 

   r = requests.get(url) 

   # time  period when acknowledgement of signal 
   # is received 
   t2 = time.time() 

   # total time taken during this process 
   tim = str(t2-t1) 

   print("Time in seconds :" + tim) 

# Pilot program 
# url address to hit
url = "http://www.google.com"
RTT(url) 

輸出

Time in seconds :0.0579478740692

引用自:https://serverfault.com/questions/984306