Пример #1
0
def read_network_interfaces():
    intDict = {}
    intDict['class'] = "NETINTERFACES"

    interfaces = ethtool.get_devices()
    for interface in interfaces:
        try:
            hwaddr = ethtool.get_hwaddr(interface)
        except:
            hwaddr = ""

        try:
            module = ethtool.get_module(interface)
        except:
            if interface == 'lo':
                module = "loopback"
            else:
                module = "Unknown"
        try:
            ipaddr = ethtool.get_ipaddr(interface)
        except:
            ipaddr = ""

        try:
            netmask = ethtool.get_netmask(interface)
        except:
            netmask = ""

        try:
            broadcast = ethtool.get_broadcast(interface)
        except:
            broadcast = ""

        intDict[interface] = {'hwaddr':hwaddr,
                              'ipaddr':ipaddr,
                              'netmask':netmask,
                              'broadcast':broadcast,
                              'module': module}

    return intDict
Пример #2
0
def get_network_info():
    try:
        import rhpl.ethtool as ethtool
    except:
        raise CX("the rhpl module is required to use this feature (is your OS>=EL3?)")

    interfaces = {}
    # get names
    inames = ethtool.get_active_devices()
    for iname in inames:
        mac = ethtool.get_hwaddr(iname)
        ip = ethtool.get_ipaddr(iname)
        nm = ethtool.get_netmask(iname)
        try:
            module = ethtool.get_module(iname)
            if module == "bridge":
                continue
        except:
            continue
        interfaces[iname] = {"ip_address": ip, "mac_address": mac, "netmask": nm}

    return interfaces