Part of the Code
Import OS import time import psutil import sys import atexit import datetime import re import array import socket import s Truct Import fcntl def check_linked (ETH): "" "" Check HW (eth0) NET physics conection "" "Buff = Array.array (' i ', [0 x0000000a, 0x00000000]) addr, length = Buff.buffer_info () arg = Struct.pack ("Pi", addr, length) data = (ETH + ' *16 ' [:] + arg sock = Socket.socket (socket.af_inet, socket.
SOCK_DGRAM) Siocethtool = 0x8946 Try:fcntl.ioctl (Sock.fileno (), Siocethtool, data) except IOError, E: Print (' Check%s lined failed, and error is%s '% (ETH,STR (e)) Sock.close () return False Soc K.close () return bool (Buff.tolist () [1]) #function to net State def getnetstate (): Dir_net_info = psutil.net_i F_addrs () List_net_key = List (Dir_net_info.keys ()) #dir_net_stats = Psutil.net_if_stats () list_net_key.reverse (
) Net_information = Psutil.net_io_counters (pernic=true) net_info= "" For Str_i in list_net_key:if Str_i = = ' lo ': Continue List_get_value=dir_net_info.get (Str_i) list_ Get_value2=list (list_get_value[0:1]) #list_get_net = Dir_net_stats.get (str_i) List_get_net_info = Net_info
Rmation.get (Str_i) #if list_get_net_info!=none: # str_get_net_info = str (list_get_net_info[0))
# Str_get_net_info2 = str (list_get_net_info[1]) str_re=re.sub (". *address= '", "", str (list_get_value2))
Str_re2=re.sub ("'. *", "", Str_re) if (Re.search (":", Str_re2))!=none:str_re2= "" If check_linked (str_i) = = False: str_3= "stoped" else:str_3= "Running" net_info + = Str_i + "" + Str_re2 + "" +str
_3+ "|" #net_info + + "-" return (Net_info)
Code copied, the format may not be correct