How to use the ethtool.get_ipaddr function in ethtool

To help you get started, we’ve selected a few ethtool examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uyuni-project / uyuni / client / rhel / spacewalk-client-tools / src / up2date_client / hardware.py View on Github external
try:
            if ethtool_present:
                module = ethtool.get_module(interface)
            else:
                driver_file = open('/sys/class/net/%s/device/uevent' % interface, 'r')
                module = driver_file.readline().split('=')[1].strip()
                driver_file.close()
        except:
            if interface == 'lo':
                module = "loopback"
            else:
                module = "Unknown"

        try:
            if ethtool_present:
                ipaddr = ethtool.get_ipaddr(interface)
            else:
                ipaddr = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr']
        except:
            ipaddr = ""

        try:
            if ethtool_present:
                netmask = ethtool.get_netmask(interface)
            else:
                netmask = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['netmask']
        except:
            netmask = ""

        try:
            if ethtool_present:
                broadcast = ethtool.get_broadcast(interface)
github kimchi-project / kimchi / model / interfaces.py View on Github external
def lookup(self, name):
        if encode_value(name) not in map(encode_value, ethtool.get_devices()):
            raise NotFoundError('KCHIFACE0001E', {'name': name})

        ipaddr = ''
        netmask = ''
        module = 'unknown'
        status = 'down'
        try:
            ipaddr = ethtool.get_ipaddr(encode_value(name))
            netmask = ethtool.get_netmask(encode_value(name))
            module = ethtool.get_module(encode_value(name))

            flags = ethtool.get_flags(encode_value(name))
            status = 'up' if flags & (
                ethtool.IFF_RUNNING | ethtool.IFF_UP) else 'down'
        except IOError:
            pass

        iface_type = netinfo.get_interface_type(name)

        return {
            'name': name,
            'type': iface_type,
            'status': status,
            'ipaddr': ipaddr,
github oVirt / ovirt-hosted-engine-setup / src / plugins / gr-he-common / network / bridge.py View on Github external
def _get_active_interface(self, valid_interfaces):
        for iface in valid_interfaces:
            try:
                if (
                    socket.getfqdn(ethtool.get_ipaddr(iface)) ==
                    socket.gethostname()
                ):
                    return iface
            except IOError:
                pass
        return valid_interfaces[0]
github cobbler / cobbler / koan / utils.py View on Github external
def get_network_info():
    interfaces = {}
    # get names
    inames = ethtool.get_devices()

    for iname in inames:
        mac = ethtool.get_hwaddr(iname)

        if mac == "00:00:00:00:00:00":
            mac = "?"

        try:
            ip = ethtool.get_ipaddr(iname)
            if ip == "127.0.0.1":
                ip = "?"
        except:
            ip = "?"

        bridge = 0
        module = ""

        try:
            nm = ethtool.get_netmask(iname)
        except:
            nm = "?"

        interfaces[iname] = {
            "ip_address": ip,
            "mac_address": mac,
github uyuni-project / uyuni / client / debian / packages-already-in-debian / python-ethtool / pifconfig.py View on Github external
def show_config(device):
        ipaddr = ethtool.get_ipaddr(device)
        netmask = ethtool.get_netmask(device)
        flags = ethtool.get_flags(device)
        print '%-9.9s' % device,
        if not (flags & ethtool.IFF_LOOPBACK):
                print "HWaddr %s" % ethtool.get_hwaddr(device),
        print '''
          inet addr:%s''' % ipaddr,
        if not (flags & (ethtool.IFF_LOOPBACK | ethtool.IFF_POINTOPOINT)):
                print "Bcast:%s" % ethtool.get_broadcast(device),
        print '''  Mask:%s
          %s
''' % (netmask, flags2str(flags))