# -*- coding: utf-8 -*-
import os
import re
p = os.popen('ping 120.26.77.101')
out = p.read()
regex = re.compile("xd7xeexb6xcc = (d+)msxa3xacxd7xeexb3xa4 = (d+)msxa3xacxc6xbdxbexf9 = (d+)ms", re.IGNORECASE)
all_result = regex.findall(out)
min_time = int(all_result[0][0])
max_time = int(all_result[0][1])
avg_time = int(all_result[0][2])
print('最短时间:' + str(min_time) + 'ms, ' + '最长时间:' + str(max_time) + 'ms, ' + '平均时间:' + str(avg_time) + 'ms')
import subprocess
import re
p = subprocess.Popen(["ping.exe", 'google.com'],
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = True)
out = p.stdout.read()
regex = re.compile("Minimum = (d+)ms, Maximum = (d+)ms, Average = (d+)ms", re.IGNORECASE)
print regex.findall(out)