Thank you of your answer of course your solution works for python3.3+ as the mine.
I think I will use only python3.3+. Moreover, I modified the script in order to work for different operating system.
Code:
for host in tqdm(hosts):
if platform == "linux" or platform == "darwin":
command=["ping", "-c", "3", "-i", "0.2", host]
timeout=0.5
else:
command=["ping", "-n", "1", host]
timeout=0.2
ping=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
try:
[out, err]=proc.communicate(timeout=2.1)
if proc.returncode == 0:
if platform == "linux" or platform == "darwin":
avgRTT=re.search("rtt min/avg/max/mdev = (\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+)", str(out)).group(2)
else:
# to do
avgRTT=re.search("", str(out))
Unfortunately, windows has different ping version than GNU/linux or mac os X that does not support the option -i and so I have to play with timeout in order to limit the time required.
Moreover, also the parsing is different.
Bookmarks