可以用来检测是否有挖矿程序在运行的一个子条件
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))