码迷,mamicode.com
首页 > 其他好文 > 详细

获取ping的最短、最长、平均时间

时间:2015-05-14 11:35:18      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:

# -*- coding: utf-8 -*-

import os
import re
p = os.popen(‘ping 120.26.77.101‘)

out = p.read()
regex = re.compile("\xd7\xee\xb6\xcc = (\d+)ms\xa3\xac\xd7\xee\xb3\xa4 = (\d+)ms\xa3\xac\xc6\xbd\xbe\xf9 = (\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)

获取ping的最短、最长、平均时间

标签:

原文地址:http://www.cnblogs.com/hushaojun/p/4502758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!