Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except:
hwaddr = ""
# slave devices can have their hwaddr changed
try:
master = os.readlink('/sys/class/net/%s/master' % interface)
except:
master = None
if master:
master_interface = os.path.basename(master)
hwaddr = get_slave_hwaddr(master_interface, interface)
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:
def show_driver(interface, args = None):
try:
driver = ethtool.get_module(interface)
except IOError:
driver = "not implemented"
try:
bus = ethtool.get_businfo(interface)
except IOError:
bus = "not available"
printtab("driver: %s" % driver)
printtab("bus-info: %s" % bus)
Returns string name of the device driver as reported by the kernel.
Tries several methods to obtain the name.
"""
if self.link_header_type == 772: # loopback header type
return 'loopback'
linkinfo = self._nl_msg.get_attr("IFLA_LINKINFO")
if linkinfo:
result = linkinfo.get_attr("IFLA_INFO_KIND")
if result and result != "unknown":
# pyroute2 tries to be too clever and second guesses the
# driver; when it fails, it fills in "unknown". We need to
# ignore it.
return result
try:
return ethtool.get_module(self.name)
except IOError:
return None
hwaddr = ethtool.get_hwaddr(interface)
except:
hwaddr = ""
# slave devices can have their hwaddr changed
try:
master = os.readlink('/sys/class/net/%s/master' % interface)
except:
master = None
if master:
master_interface = os.path.basename(master)
hwaddr = get_slave_hwaddr(master_interface, interface)
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:
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,
'netmask': netmask,
'module': module,