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

Method _detect_default_interface

actions/scanning.py:155–187  ·  view source on GitHub ↗

Detect the active network interface using ip route.

()

Source from the content-addressed store, hash-verified

153
154 @staticmethod
155 def _detect_default_interface():
156 """Detect the active network interface using ip route."""
157 try:
158 result = subprocess.run(
159 ['ip', 'route', 'show', 'default'],
160 capture_output=True, text=True, timeout=5
161 )
162 # Parse: default via 172.16.52.1 dev br-lan ...
163 for line in result.stdout.strip().splitlines():
164 parts = line.split()
165 if 'dev' in parts:
166 idx = parts.index('dev')
167 if idx + 1 < len(parts):
168 return parts[idx + 1]
169 except Exception:
170 pass
171 # Fallback: find first non-lo interface with an IP
172 try:
173 result = subprocess.run(
174 ['ip', '-o', '-4', 'addr', 'show'],
175 capture_output=True, text=True, timeout=5
176 )
177 for line in result.stdout.strip().splitlines():
178 # Format: 3: br-lan inet 172.16.52.1/24 brd ...
179 parts = line.split()
180 if len(parts) >= 4 and '127.0.0.1' not in line:
181 iface = parts[1].rstrip(':')
182 if iface != 'lo':
183 return iface
184 except Exception:
185 pass
186 from shared import detect_wifi_interface
187 return detect_wifi_interface('auto')
188
189 @staticmethod
190 def _is_valid_mac(value):

Callers 1

__init__Method · 0.95

Calls 3

detect_wifi_interfaceFunction · 0.90
runMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected