diff options
-rwxr-xr-x | bin/network_info | 96 | ||||
-rw-r--r-- | units/ethernet/jobs.pxu | 4 | ||||
-rw-r--r-- | units/networking/jobs.pxu | 3 |
3 files changed, 4 insertions, 99 deletions
diff --git a/bin/network_info b/bin/network_info deleted file mode 100755 index d3ff5df..0000000 --- a/bin/network_info +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys -import subprocess -import socket -import fcntl -import struct - -SYS_PATH = '/sys/class/net' - - -def _read_file(file): - source = open(file, 'r') - content = source.read() - source.close() - return content - - -def get_connected(interface): - STATUS = ('No', 'Yes') - carrier_file = os.path.join(SYS_PATH, interface, 'carrier') - - carrier = 0 - try: - carrier = int(_read_file(carrier_file)) - except IOError: - pass - - return STATUS[carrier] - - -def get_ip_address(interface): - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - return socket.inet_ntoa(fcntl.ioctl( - s.fileno(), - 0x8915, # SIOCGIFADDR - struct.pack('256s', interface[:15].encode()) - )[20:24]) - - -def get_ipv6_address(interface): - cmd = ['/sbin/ip', '-6', '-o', 'addr', 'show', - 'dev', interface, 'scope', 'link'] - proc = subprocess.check_output(cmd, universal_newlines=True) - ipaddr = proc.split()[3].strip() - return ipaddr - - -def get_mac_address(interface): - address_file = os.path.join(SYS_PATH, interface, 'address') - - address = '' - try: - address = _read_file(address_file).strip() - except IOError: - pass - - return address - - -def get_speed(interface): - speed_file = os.path.join(SYS_PATH, interface, 'speed') - - speed = '' - try: - speed = _read_file(speed_file).strip() - except IOError: - pass - - return speed - - -def main(args): - for interface in args: - connected = get_connected(interface) - print("Interface: %s" % interface) - print("Connected: %s" % connected) - try: - print("IPv4: %s" % get_ip_address(interface)) - except IOError: - print("IPv4: n/a") - try: - print("IPv6 (link local): %s" % get_ipv6_address(interface)) - except IOError: - print("IPv6 (link local): n/a") - except: - print("IPv6 (link local): n/a") - print("MAC: %s" % get_mac_address(interface)) - print("Connect Speed: %s\n" % get_speed(interface)) - - return 0 - - -if __name__ == "__main__": - sys.exit(main(sys.argv[1:])) diff --git a/units/ethernet/jobs.pxu b/units/ethernet/jobs.pxu index 7c8d569..103a7b3 100644 --- a/units/ethernet/jobs.pxu +++ b/units/ethernet/jobs.pxu @@ -18,8 +18,8 @@ id: ethernet/info_automated requires: executable.name == 'ip' device.category == 'NETWORK' -command: udev_resource -f NETWORK | awk "/interface: / { print \$2 }" | xargs -n 1 network_info -estimated_duration: 30.0 +command: network_device_info.py detect NETWORK +estimated_duration: 2.0 _summary: Gather info on current state of network devices _description: diff --git a/units/networking/jobs.pxu b/units/networking/jobs.pxu index 360aaf2..c5f5c9f 100644 --- a/units/networking/jobs.pxu +++ b/units/networking/jobs.pxu @@ -14,7 +14,8 @@ category_id: com.canonical.plainbox::networking id: networking/info_device{__index__}_{interface} _summary: Network Information of device {__index__} ({interface}) estimated_duration: 1.0 -command: network_info {interface} | zenity --text-info --title="{interface}" +command: + network_device_info.py info NETWORK --interface {interface} | zenity --text-info --title="{interface}" _description: PURPOSE: This test will check the network device {__index__} ({interface}) |