aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugeni Dodonov <eugeni@mandriva.com>2009-09-24 11:49:28 -0300
committerEugeni Dodonov <eugeni@mandriva.com>2009-09-24 11:49:28 -0300
commit7b78c3c074057b142aea9e08b7e7b37046a17aa8 (patch)
tree071617ddc533c55fd08ff5fe5fb02c9ea19907e4
parent4fca00f85539a68f193acc2069d6e2d7202eb9e8 (diff)
downloadnet_monitor-7b78c3c074057b142aea9e08b7e7b37046a17aa8.tar
net_monitor-7b78c3c074057b142aea9e08b7e7b37046a17aa8.tar.gz
net_monitor-7b78c3c074057b142aea9e08b7e7b37046a17aa8.tar.bz2
net_monitor-7b78c3c074057b142aea9e08b7e7b37046a17aa8.tar.xz
net_monitor-7b78c3c074057b142aea9e08b7e7b37046a17aa8.zip
monitoring network addresses
-rwxr-xr-xnet_monitor.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/net_monitor.py b/net_monitor.py
index 7360f5f..0c0c409 100755
--- a/net_monitor.py
+++ b/net_monitor.py
@@ -12,8 +12,11 @@ import getopt
import sys
import traceback
-from threading import Thread
-from Queue import Queue
+# for address
+import socket
+import fcntl
+import struct
+
import time
import textwrap
@@ -28,6 +31,19 @@ except IOError:
ifaces = {}
HISTOGRAM_SIZE=50
+
+def get_ip_address(ifname):
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ try:
+ return socket.inet_ntoa(fcntl.ioctl(
+ s.fileno(),
+ 0x8915, # SIOCGIFADDR
+ struct.pack('256s', ifname[:15])
+ )[20:24])
+ except:
+ # no address
+ return _("No address assigned")
+
def readnet():
"""Reads values from /proc/net/dev"""
net = {}
@@ -289,6 +305,7 @@ class Monitor:
'widget_histo_out': None,
'graph': None,
'histogram': [],
+ 'address': "",
}
iface_stat = self.build_iface_stat(iface)
self.notebook.append_page(iface_stat, gtk.Label(iface))
@@ -347,7 +364,9 @@ class Monitor:
('widget_speed_in', speed_in),
('widget_speed_out', speed_out),
('widget_histo_in', histo_in),
- ('widget_histo_out', histo_out)]:
+ ('widget_histo_out', histo_out),
+ ('widget_address', get_ip_address(iface))
+ ]:
if widget in self.ifaces[iface]:
self.ifaces[iface][widget].set_text(str(value))
else:
@@ -444,6 +463,9 @@ class Monitor:
vbox.pack_start(iface_h, False, False)
iface_s, iface_status = self.build_value_pair(sizegroup, _("Device status:"), _("Up"))
vbox.pack_start(iface_s, False, False)
+ iface_addr_s, iface_addr = self.build_value_pair(sizegroup, _("Address:"))
+ self.ifaces[iface]["widget_address"] = iface_addr
+ vbox.pack_start(iface_addr_s, False, False)
# traffic
total_in_h, total_in = self.build_value_pair(sizegroup, _("Received data:"))