#!/usr/bin/python3 # -*- coding: utf-8 -*- from curses import color_pair as get_pair network_interfaces = ('eth0',) # C'est pour importer des modules du repertoire parent from os.path import dirname from sys import path as pythonpath pythonpath.insert (0, dirname (dirname (__file__))) from utils import groupbythree def netdevs(iface): ''' RX and TX statistics for the iface network interface ''' from collections import namedtuple with open('/proc/net/dev') as f: net_dump = f.readlines() device_data={} data = namedtuple('data',['rx','tx']) for line in net_dump[2:]: line = line.split(':') device_data[line[0].strip()] = data(int (line[1].split()[0]), int (line[1].split()[8])) return (device_data [iface].rx, device_data [iface].tx) def main (line, screen): for i in ifaces: i [2] = i [1] i [1] = netdevs (i [0]) screen.addstr (line, 0, '-->', get_pair (5)) screen.addstr (line, 3, 'Réseau :', get_pair (1)) line += 1 table = [] for i in ifaces: table.append ((i [0], groupbythree (i[1][0]), groupbythree (i[1][1]), groupbythree (i[1][0] - i[2][0]), groupbythree (i[1][1] - i[2][1]))) max_lengths = [0, 0, 0, 0, 0] for i in table: length = len (i [0]) if length > max_lengths [0]: max_lengths [0] = length length = len (i [1]) if length > max_lengths [1]: max_lengths [1] = length length = len (i [2]) if length > max_lengths [2]: max_lengths [2] = length length = len (i [3]) if length > max_lengths [3]: max_lengths [3] = length length = len (i [4]) if length > max_lengths [4]: max_lengths [4] = length for i in table: x = 0 f = '%-' + str (max_lengths [0]) + 's:' screen.addstr (line, x, f%(i [0]), get_pair (2)) x += max_lengths [0] + 2 screen.addstr (line, x, '↓', get_pair (1)) f = '%' + str (max_lengths [1]) + 's' screen.addstr (line, x + 2, f%((i[1])), get_pair (3)) screen.addstr (line, x + 3 + max_lengths [1], 'o', get_pair (1)) x += max_lengths [1] + 5 screen.addstr (line, x,'↑', get_pair (1)) f = '%' + str (max_lengths [2]) + 's' screen.addstr (line, x + 2, f%((i[2])), get_pair (3)) screen.addstr (line, x + 3 + max_lengths [2], 'o', get_pair (1)) x += max_lengths [2] + 5 screen.addstr (line, x, '↓', get_pair (1)) f = '%' + str (max_lengths [3]) + 's' screen.addstr (line, x + 2, f%((i[3])), get_pair (3)) screen.addstr (line, x + 3 + max_lengths [3], 'o/s', get_pair (1)) x += max_lengths [3] + 7 screen.addstr (line, x, '↑', get_pair (1)) f = '%' + str (max_lengths [4]) + 's' screen.addstr (line, x + 2, f%((i[4])), get_pair (3)) screen.addstr (line, x + 3 + max_lengths [4], 'o/s', get_pair (1)) x += max_lengths [4] + 7 line += 1 return (line) ifaces = [] for i in network_interfaces: ifaces.append ([i, (0,0), (0,0)])