python获取PING结果
# -*- coding: utf-8 -*- import subprocess
import re def get_ping_result(ip_address):
p = subprocess.Popen(["ping.exe", ip_address], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
out = p.stdout.read().decode('gbk') reg_receive = '已接收 = \d'
match_receive = re.search(reg_receive, out) receive_count = -1 if match_receive:
receive_count = int(match_receive.group()[6:]) if receive_count > 0: #接受到的反馈大于0,表示网络通
reg_min_time = '最短 = \d+ms'
reg_max_time = '最长 = \d+ms'
reg_avg_time = '平均 = \d+ms' match_min_time = re.search(reg_min_time, out)
min_time = int(match_min_time.group()[5:-2]) match_max_time = re.search(reg_max_time, out)
max_time = int(match_max_time.group()[5:-2]) match_avg_time = re.search(reg_avg_time, out)
avg_time = int(match_avg_time.group()[5:-2]) return [receive_count, min_time, max_time, avg_time]
else:
print('网络不通,目标服务器不可达!')
return [0, 9999, 9999, 9999] if __name__ == '__main__':
ping_result = get_ping_result('114.80.83.69')
print(ping_result)
python获取PING结果的更多相关文章
- 使用shell/python获取hostname/fqdn释疑
一直以来被Linux的hostname和fqdn(Fully Qualified Domain Name)困惑了好久,今天专门抽时间把它们的使用细节弄清了. 一.设置hostname/fqdn 在Li ...
- 使用shell/python获取hostname/fqdn释疑(转)
一直以来被Linux的hostname和fqdn(Fully Qualified Domain Name)困惑了好久,今天专门抽时间把它们的使用细节弄清了. 一.设置hostname/fqdn 在Li ...
- HCNP学习笔记之ICMP协议与ping原理以及用Python实现ping
一.ICMP协议分析 ICMP:Internet控制报文协议.由于IP协议并不是一个可靠的协议,它不保证数据被成功送达,那么,如何才能保证数据的可靠送达呢? 这里就需要使用到一个重要的协议模块ICMP ...
- python 获取日期
转载 原文:python 获取日期 作者:m4774411wang python 获取日期我们需要用到time模块,比如time.strftime方法 time.strftime('%Y-%m-% ...
- python获取字母在字母表对应位置的几种方法及性能对比较
python获取字母在字母表对应位置的几种方法及性能对比较 某些情况下要求我们查出字母在字母表中的顺序,A = 1,B = 2 , C = 3, 以此类推,比如这道题目 https://project ...
- python获取文件大小
python获取文件大小 # !/usr/bin/python3.4 # -*- coding: utf-8 -*- import os # 字节bytes转化kb\m\g def formatSiz ...
- python 获取一个列表有多少连续列表
python 获取一个列表有多少连续列表 例如 有列表 [1,2,3] 那么连续列表就是 [1,2],[2,3],[1,2,3] 程序实现如下: 运行结果:
- [python实用代码片段]python获取当前时间的前一天,前一周,前一个月
python获取当前时间的前一天,前一周,前一个月. 实用python的datetime.timedelta方法,避免了有的月份是30和31等不同的情况. 获取前一个月的时间,方法实现:首先datet ...
- Python获取目录、文件的注意事项
Python获取指定路径下的子目录和文件有两种方法: os.listdir(dir)和os.walk(dir),前者列出dir目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >> ...
随机推荐
- Fragment Transactions & Activity State Loss
转自:http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html The foll ...
- Java 8函数式接口functional interface的秘密
Java 8函数式接口functional interface的秘密 2014年10月29日 17:52:55 西瓜可乐520 阅读数:3729 目录 [−] JDK 8之前已有的函数式接口 新定 ...
- Mock 模拟测试简介及 Mockito 使用入门
Mock 是什么mock 测试就是在测试过程中,对于某些不容易构造或者不容易获取的对象,用一个虚拟的对象来创建以便测试的测试方法.这个虚拟的对象就是mock对象.mock对象就是真实对象在调试期间的代 ...
- error “Device supports x86, but APK only supports armeabi-v7a”
checkout the build.gradle from module:app. It turns out that there's a such config: ndk { abiFilters ...
- Check failed: mdb_status == 0 (13 vs. 0) Permission denied
文件权限问题. chown或者chmod即可 另外注意lmdb文件的权限
- GDSL 1.7 发布,C语言通用数据结构库
GDSL 1.7 修复了 interval-heap 模块的一个小 bug. GDSL (通用数据结构库) 包含一组程序用于操作各种数据结构.这是一个可移植的库,完全由 ANSI C 编写.为 C 开 ...
- SQLServer 日期函数大全 SQLServer 时间函数大全
原文地址:https://www.cnblogs.com/zhangpengnike/p/6122588.html 一.统计语句 1.--统计当前[>当天00点以后的数据] SELECT * F ...
- hyper-v 尝试更改 状态时 应用程序遇到错误 无法初始化
刚还原了一个问题,现在 又来一个: 让我崩溃的微软 hyper-v.这次错误 提示也没了. http://social.technet.microsoft.com/Forums/de-DE/751b2 ...
- 修改visual studio2010 的快捷键,使用ctrl+W 关闭当前文档
废话不多说,打开visualstudio 的菜单 [工具]->[选项].定位到 环境->键盘. 找到光口.关闭文档窗口.把默认的ctrl+F4移除,因为这两个组合键按起来太麻烦,太累了.再 ...
- 第二十五章 springboot + hystrixdashboard
注意: hystrix基本使用:第十九章 springboot + hystrix(1) hystrix计数原理:附6 hystrix metrics and monitor 一.hystrixdas ...