# https://github.com/alessandromaggio/pythonping
import pythonping
A = pythonping.ping('8.8.8.8')
A
Reply from 8.8.8.8, 29 bytes in 6.11ms Reply from 8.8.8.8, 29 bytes in 4.61ms Reply from 8.8.8.8, 29 bytes in 3.16ms Reply from 8.8.8.8, 29 bytes in 3.76ms Round Trip Times min/avg/max is 3.16/4.41/6.11 ms
vars(A)
{'_responses': [Reply from 8.8.8.8, 29 bytes in 6.11ms, Reply from 8.8.8.8, 29 bytes in 4.61ms, Reply from 8.8.8.8, 29 bytes in 3.16ms, Reply from 8.8.8.8, 29 bytes in 3.76ms], 'stats_packets_sent': 4, 'stats_packets_returned': 4, 'verbose': False, 'output': <ipykernel.iostream.OutStream at 0x133ab6a54e0>, 'rtt_avg': 0.0044096249985159375, 'rtt_min': 0.0031579999995301478, 'rtt_max': 0.006113199997344054}
vars(A._responses[0])
{'message': 45 60 00 1d 00 00 00 00 74 01 73 bd 08 08 08 08 c0 a8 02 0b 00 00 23 dd 97 22 01 00 44, 'time_elapsed': 0.006113199997344054, 'source_request': 08 00 1b dd 97 22 01 00 44, 'repr_format': 'legacy'}
A._responses[0].time_elapsed
0.006113199997344054
type(A._responses[0].time_elapsed)
float
B = pythonping.ping('8.8.8.8', count=100)
B_list = [response.time_elapsed for response in B._responses]
type(B_list)
list
import numpy as np
B_np = np.array(B_list)
import matplotlib.pyplot as plt
plt.xlabel("Ping")
plt.ylabel("Response time (ms)")
plt.plot(1000*B_np)
[<matplotlib.lines.Line2D at 0x133ada80a60>]
C = pythonping.ping('8.8.8.8', count=1000, interval=1)
C_list = [response.time_elapsed for response in C._responses]
C_np = np.array(C_list)
plt.title("9:10 PM January 1, 2022")
plt.xlabel("Ping")
plt.ylabel("Response time (ms)")
plt.plot(1000*C_np)
[<matplotlib.lines.Line2D at 0x133adc5ee90>]
np.savetxt('01-01-2023-910pm.csv', 1000*C_np, fmt='%.6f')