Python检测网络延迟的代码
本文讲述了Python检测网络延迟的代码。分享给大家供大家参考,具体如下:
#!/usr/bin/env python # coding: utf-8 # coding: cp950 ''''' Create Date: 2012-11-06 Version: 1.0 Description: Detection host survival Author: Victor QQ: 1409175531 ''' ''''' Please run the script with root ''' import ping import sys def help(): print ''''' Usage: %s <Dest_addr> <percent loss packages> <max round trip time> ''' % (sys.argv[0]) try: result = ping.quiet_ping(sys.argv[1], timeout=2, count=10, psize=64) if int(result[0]) == 100: print 'Critical - 宕机, 丢包率:%s%% | 报警阀值: >= %s%% 或 >=%s ms' % (result[0], int(sys.argv[2]), int(sys.argv[3])) sys.exit(2) else: max_time = round(result[1], 2) if int(result[0]) < int(sys.argv[2]) and int(result[1]) < int(sys.argv[3]): print 'OK - 丢包率:%s%%, 最大响应时间:%s ms | 报警阀值: >= %s%% 或 >=%s ms' % (result[0], max_time, int(sys.argv[2]), int(sys.argv[3])) sys.exit(0) elif int(result[0]) >= int(sys.argv[2]) or int(result[1]) >= int(sys.argv[3]): print 'Warning - 丢包率:%s%%, 最大响应时间:%s ms | 报警阀值: >= %s%% 或 >=%s ms' % (result[0], max_time, int(sys.argv[2]), int(sys.argv[3])) sys.exit(1) else: print 'Unknown' sys.exit(3) except IndexError: help() sys.exit(3)
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16