Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
master = None
if master:
master_interface = os.path.basename(master)
hwaddr = get_slave_hwaddr(master_interface, interface)
try:
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)
try:
module = ethtool.get_module(interface)
except:
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))