From f10f6dcbb0a7eeb00443261495f15c0cf361495b Mon Sep 17 00:00:00 2001 From: Adrien Beudin Date: Fri, 4 Oct 2013 12:23:25 +0200 Subject: [PATCH] ifconfig ok --- yunohost_monitor.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/yunohost_monitor.py b/yunohost_monitor.py index c683f8af..e3ac18e6 100644 --- a/yunohost_monitor.py +++ b/yunohost_monitor.py @@ -38,11 +38,22 @@ except ImportError: sys.stderr.write('apt-get install python-yaml\n') sys.exit(1) import json +import socket +import fcntl +import struct if not __debug__: import traceback s = xmlrpclib.ServerProxy('http://127.0.0.1:61209') +def get_ip_address(ifname): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + return socket.inet_ntoa(fcntl.ioctl( + s.fileno(), + 0x8915, # SIOCGIFADDR + struct.pack('256s', ifname[:15]) + )[20:24]) + def bytes2human(n): symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y') prefix = {} @@ -126,8 +137,13 @@ def monitor_info(memory=False, cpu=False, disk=False, ifconfig=False, uptime=Fal result = {} for k, fs in enumerate(json.loads(s.getNetwork())): interface = fs['interface_name'] - del fs['interface_name'] - result[interface] = fs + if interface != "lo": + ip = get_ip_address(str(interface)) + del fs['interface_name'] + result[ip] = fs + else: + del fs['interface_name'] + result[interface] = fs return result elif disk: