MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / _check_ethernet_carrier

Function _check_ethernet_carrier

wifi_interfaces.py:252–281  ·  view source on GitHub ↗

Check if an Ethernet interface has a physical connection (carrier).

(interface_name: str)

Source from the content-addressed store, hash-verified

250
251
252def _check_ethernet_carrier(interface_name: str) -> bool:
253 """Check if an Ethernet interface has a physical connection (carrier)."""
254 try:
255 # Check carrier file in sysfs
256 result = subprocess.run(
257 ['cat', f'/sys/class/net/{interface_name}/carrier'],
258 capture_output=True,
259 text=True,
260 timeout=2
261 )
262 if result.returncode == 0:
263 carrier = result.stdout.strip()
264 return carrier == '1'
265 except Exception as exc:
266 logger.debug(f"Unable to check carrier for {interface_name}: {exc}")
267
268 # Fallback: check if interface is UP and has an IP
269 try:
270 result = subprocess.run(
271 ['ip', 'link', 'show', interface_name],
272 capture_output=True,
273 text=True,
274 timeout=2
275 )
276 if result.returncode == 0:
277 return 'state UP' in result.stdout
278 except Exception:
279 pass
280
281 return False
282
283
284def gather_ethernet_interfaces(default_interface: str = 'eth0') -> List[Dict]:

Callers 1

Calls 2

debugMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected