zoukankan      html  css  js  c++  java
  • python检测当前网卡流量信息,用于查看实时网速

    可以用来检测是否有挖矿程序在运行的一个子条件

     1 # coding:utf-8
     2 __author__ = 'chenhuachao'
     3 import wmi
     4 import time
     5 import platform
     6 
     7 def get_network_flow(os):
     8     '''监控window平台下网卡的实时的流量信息
     9     通过当前总流量和一秒后的总流量的差值,来统计实时的网卡流量信息;
    10     返回的流量单位是KB
    11     '''
    12     if os == "Windows":
    13         c = wmi.WMI()
    14         for interfacePerTcp in c.Win32_PerfRawData_Tcpip_TCPv4():
    15             sentflow = float(interfacePerTcp.SegmentsSentPersec)  #已发送的流量
    16             receivedflow = float(interfacePerTcp.SegmentsReceivedPersec) #接收的流量
    17             present_flow = sentflow+receivedflow    #算出当前的总流量
    18         time.sleep(1)
    19         for interfacePerTcp in c.Win32_PerfRawData_Tcpip_TCPv4():
    20            sentflow = float(interfacePerTcp.SegmentsSentPersec)  #已发送的流量
    21            receivedflow = float(interfacePerTcp.SegmentsReceivedPersec) #接收的流量
    22            per_last_present_flow = sentflow+receivedflow     #算出1秒后当前的总流量
    23         present_network_flow = (per_last_present_flow - present_flow)/1024
    24         print("当前流量为:{0}KB".format("%.2f"%present_network_flow))
    25         return "%.2f"%present_network_flow
    26 
    27 if __name__ =="__main__":
    28     os = platform.system()
    29     while 1:
    30         flow = get_network_flow(os)
    31         print("{0}KB".format(flow))
  • 相关阅读:
    Direct UI 思想阐述(好多相关文章)
    GetSystemTimeAsFileTime讲解(从1601年1月1日到目前经过的纳秒)
    WPF的消息机制
    CEdit 样式与消息 解析
    vcredist_x86.exe 静默安装方法
    iOS 开发问题集锦(一)
    EM算法详解
    BCP导入导出MsSql
    为什么不能在子类或外部发布C#事件
    HTML5 拖放及排序的简单实现
  • 原文地址:https://www.cnblogs.com/ljy1227476113/p/10913484.html
Copyright © 2011-2022 走看看