Question: Python import subprocess import datetime import sys import os from time import sleep # Collect input parameters # Taking the args from command line host
Python
import subprocess import datetime import sys import os from time import sleep
# Collect input parameters # Taking the args from command line host = sys.argv[1]
number_of_times = int(sys.argv[2]) # Iterating the given number of times for i in range(number_of_times): cmd = 'ping -c 1 ' + host fullPingResult = "" # forming command try: fullPingResult = os.popen(cmd).read() print(datetime.datetime.now().strftime("%H:%M:%S"), fullPingResult) #print(fullPingResult)
except Exception as e: print("Error: " + cmd + " " + str(e)) ## app file name ipaddress number to try ## command line type = python pynger3.py 127.0.0.1 10
We need the time=32ms written to a pinger3.csv file! can you help
C:\Users rrob\Desktop>python pinger3.py google.com 3 08:24:30 Pinging google.com [216.58.194.46] with 32 bytes of data: Reply from 216.58.194.46: bytes=32 time=22ms TTL=128 Reply from 216.58.194.46: bytes=32 time=26ms TTL=128 Reply from 216.58.194.46: bytes=32 time=29ms TTL=128 Reply from 216.58.194.46: bytes=32 time=32ms TTL=128
Ping statistics for 216.58.194.46: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 22ms, Maximum = 32ms, Average = 27ms
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
