Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_interfaces(self):
ifcfg.Parser = WindowsParser
interfaces = ifcfg.interfaces(ifconfig=ipconfig_out.WINDOWS_10_ETH)
res = len(interfaces) > 0
ok_(res)
def test_ifcfg(self):
ifcfg.distro = 'Linux'
ifcfg.Parser = UnixIPParser
interfaces = ifcfg.interfaces(ifconfig=ip_out.LINUX)
res = len(interfaces) > 0
ok_(res)
def test_ifcfg(self):
ifcfg.distro = 'Linux'
ifcfg.Parser = LinuxParser
interfaces = ifcfg.interfaces(ifconfig=ifconfig_out.LINUX)
res = len(interfaces) > 0
ok_(res)
def report(self):
"""Print system and ROS network information."""
# check ifcfg import for windows and osx users
try:
ifcfg_ifaces = ifcfg.interfaces()
except NameError:
doctor_warn('ifcfg is not imported. Unable to generate network report.')
return Report('')
network_report = Report('NETWORK CONFIGURATION')
for iface in ifcfg_ifaces.values():
for k, v in iface.items():
if v:
network_report.add_to_report(k, v)
return network_report
def get_0_5_mac_address():
# first, try using ifcfg
interfaces = []
try:
interfaces = ifcfg.interfaces().values()
except: # noqa: E722
pass
for iface in sorted(interfaces, key=_device_sort_key):
ether = iface.get("ether")
if ether and not _mac_is_local(ether):
return _do_salted_hash(ether)
# fall back to trying uuid.getnode
mac = uuid.getnode()
if not _mac_is_multicast(
mac
): # when uuid.getnode returns a fake MAC, it marks as multicast
return _do_salted_hash(_mac_int_to_ether(mac))
return ""
def check(self):
"""Check network configuration."""
result = Result()
# check ifcfg import for windows and osx users
try:
ifcfg_ifaces = ifcfg.interfaces()
except NameError:
result.add_error('ERROR: ifcfg is not imported. Unable to run network check.')
return result
has_loopback, has_non_loopback, has_multicast = _check_network_config_helper(ifcfg_ifaces)
if not _is_unix_like_platform():
if not has_loopback and not has_non_loopback:
# no flags found, otherwise one of them should be True.
print('No flags found. \
Run `ipconfig` on cmd to check network interfaces.')
return result
if not has_loopback:
result.add_error('ERROR: No loopback IP address is found.')
if not has_non_loopback:
result.add_warning('Only loopback IP address is found.')
if not has_multicast:
def _check_interface(self, *args, **kwargs):
prev_ip = self.ip
ip = None
iface = self.config.get_config()["interface"]
if iface.strip():
try:
for interface in ifcfg.interfaces().values():
if interface["device"] == iface:
ip = interface["inet"]
break
if ip is None and platform.system() == "Linux":
iff = pyiface.iface.Interface(name=str(iface))
ip = iff.ip_str()
if ip is not None and not deluge.common.is_ip(ip):
self.log.info("Invalid IP returned for interface '%s': %s" % (iface, ip), gtkui=True)
ip = None
except TypeError as e:
self.log.error("TypeError: %s" % e, gtkui=True)
return ip
else:
ip = ""
iface = ""
def main():
print(json.dumps(ifcfg.interfaces(), indent=2))