MCPcopy
hub / github.com/smittix/intercept / _detect_interfaces

Method _detect_interfaces

intercept_agent.py:499–633  ·  view source on GitHub ↗

Detect WiFi interfaces and Bluetooth adapters.

(self, capabilities: dict)

Source from the content-addressed store, hash-verified

497 return capabilities
498
499 def _detect_interfaces(self, capabilities: dict):
500 """Detect WiFi interfaces and Bluetooth adapters."""
501 import platform
502
503 interfaces = capabilities.get('interfaces', {})
504
505 # Detect WiFi interfaces
506 if platform.system() == 'Darwin': # macOS
507 try:
508 result = subprocess.run(
509 ['networksetup', '-listallhardwareports'],
510 capture_output=True, text=True, timeout=5
511 )
512 lines = result.stdout.split('\n')
513 for i, line in enumerate(lines):
514 if 'Wi-Fi' in line or 'AirPort' in line:
515 port_name = line.replace('Hardware Port:', '').strip()
516 for j in range(i + 1, min(i + 3, len(lines))):
517 if 'Device:' in lines[j]:
518 device = lines[j].split('Device:')[1].strip()
519 interfaces['wifi_interfaces'].append({
520 'name': device,
521 'display_name': f'{port_name} ({device})',
522 'type': 'internal',
523 'monitor_capable': False
524 })
525 break
526 except (FileNotFoundError, subprocess.TimeoutExpired, subprocess.SubprocessError):
527 pass
528 else: # Linux
529 try:
530 result = subprocess.run(
531 ['iw', 'dev'],
532 capture_output=True, text=True, timeout=5
533 )
534 current_iface = None
535 for line in result.stdout.split('\n'):
536 line = line.strip()
537 if line.startswith('Interface'):
538 current_iface = line.split()[1]
539 elif current_iface and 'type' in line:
540 iface_type = line.split()[-1]
541 interfaces['wifi_interfaces'].append({
542 'name': current_iface,
543 'display_name': f'Wireless ({current_iface}) - {iface_type}',
544 'type': iface_type,
545 'monitor_capable': True
546 })
547 current_iface = None
548 except (FileNotFoundError, subprocess.TimeoutExpired, subprocess.SubprocessError):
549 # Fall back to iwconfig
550 try:
551 result = subprocess.run(
552 ['iwconfig'],
553 capture_output=True, text=True, timeout=5
554 )
555 for line in result.stdout.split('\n'):
556 if 'IEEE 802.11' in line:

Callers 2

detect_capabilitiesMethod · 0.95
_check_available_devicesFunction · 0.45

Calls 4

getMethod · 0.80
replaceMethod · 0.80
matchMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected