Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_network_interfaces():
intDict = {}
intDict['class'] = "NETINTERFACES"
if not ethtool_present and not netifaces_present:
# ethtool is not available on non-linux platforms (as kfreebsd), skip it
sys.stderr.write("Warning: information about network interfaces could not be retrieved on this platform.\n")
return intDict
if ethtool_present:
interfaces = list(set(ethtool.get_devices() + ethtool.get_active_devices()))
else:
interfaces = netifaces.interfaces()
for interface in interfaces:
try:
if ethtool_present:
hwaddr = ethtool.get_hwaddr(interface)
else:
hwaddr = netifaces.ifaddresses(interface)[netifaces.AF_LINK][0]['addr']
except:
hwaddr = ""
# slave devices can have their hwaddr changed
try:
master = os.readlink('/sys/class/net/%s/master' % interface)
except:
def read_network_interfaces():
intDict = {}
intDict['class'] = "NETINTERFACES"
interfaces = list(set(ethtool.get_devices() + ethtool.get_active_devices()))
for interface in interfaces:
try:
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)
def run_cmd(cmd, interface, args):
global tab, all_devices
active_devices = ethtool.get_active_devices()
if not interface:
tab = " "
for interface in all_devices:
inactive = " (not active)"
if interface in active_devices:
inactive = ""
print "%s%s:" % (interface, inactive)
cmd(interface, args)
else:
cmd(interface, args)
def checkLocalHostname(self):
# This is missing and not used on rhel5
import ethtool
self.status = "OK"
self.rc = True
self.message = "Local hostname is correct."
try:
localip = map(ethtool.get_ipaddr, ethtool.get_active_devices())
localip = filter(lambda x: x != "127.0.0.1", localip)
except:
logging.error("ethtool error", exc_info=True)
localip = ()
try:
fqdnip = socket.gethostbyname(socket.gethostname())
except:
logging.error("gethostbyname error", exc_info=True)
fqdnip = None
if fqdnip is None or fqdnip not in localip:
if len(localip) < 1:
self.message = "Unable to get local ip addresses."
elif fqdnip is None:
self.message = "Unable to resolve local hostname."
def _has_network(self):
return [i for i in ethtool.get_active_devices() if i != 'lo']