Question
Write a python script that collects ping latency. Script Command: python pinger.py Command Description: To launch the script file (pinger.py), we give the script the
Write a python script that collects ping latency.
Script Command:
python pinger.py
Command Description: To launch the script file (pinger.py), we give the script the 2 arguments, the address and the number of pings to collect:
address: A string of the address to ping.
pings_to_collect: An integer of how many pings we want the script to collect data for. Each ping is separated by one second.
Ex. Input:
To ping google 120 times: python pinger.py google.com 120
Script Output:
Format:
,
Clock_Time: The system's clock time. The format should be hour:minute:second
Ping_in_ms: The result of the ping, only in milliseconds (as an integer). If the ping fails, report the value as -1.
Ex. Output:
13:01:40,54
13:01:41,60
13:01:42,-1
13:01:43,61
Notes:
The ping call will fail sometimes. Do not assume a ping response will returned within a second. So in your ping loop, wait until a response is returned (either with a ping or timeout) before waiting a second to start the next loop iteration.
This is my code but cannot make it stop or put date format. Can you help? Please print answer
-----------
import subprocess import datetime while 1: try: subprocess.check_output(['ping -l 1000 www.google.com c- 100']) except: print("Ping google.com:", datetime.datetime.now())
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started