Diagnose ZAP connectivity and configuration issues
()
| 18273 | |
| 18274 | result = session.backfill_gps_from_track() |
| 18275 | return jsonify({ |
| 18276 | 'session_id': session.session_id, |
| 18277 | 'backfilled': result |
| 18278 | }) |
| 18279 | except Exception as e: |
| 18280 | logger.error(f"Wardriving backfill error: {e}") |
| 18281 | return jsonify({'error': str(e)}), 500 |
| 18282 | |
| 18283 | |
| 18284 | @app.route('/api/wardriving/device_name', methods=['POST']) |
| 18285 | def wardriving_set_device_name(): |
| 18286 | """Set device name for wardriving sessions.""" |
| 18287 | try: |
| 18288 | data = request.get_json(silent=True) or {} |
| 18289 | name = data.get('name', '').strip()[:64] # Max 64 chars |
| 18290 | shared_data.config['wardriving_device_name'] = name |
| 18291 | shared_data.save_config() |
| 18292 | engine = _get_wardriving_engine() |
| 18293 | engine.device_name = name |
| 18294 | return jsonify({'success': True, 'device_name': name}) |
| 18295 | except Exception as e: |
| 18296 | return jsonify({'error': str(e)}), 500 |
| 18297 | |
| 18298 | @app.route('/api/wardriving/wipe', methods=['POST']) |
| 18299 | def wardriving_wipe_data(): |
| 18300 | """Delete all wardriving session data.""" |
| 18301 | try: |
| 18302 | engine = _get_wardriving_engine() |
| 18303 | result = engine.wipe_all_data() |
| 18304 | if 'error' in result: |
| 18305 | return jsonify(result), 409 |
| 18306 | return jsonify(result) |
| 18307 | except Exception as e: |
| 18308 | logger.error(f"Wardriving wipe error: {e}") |
| 18309 | return jsonify({'error': str(e)}), 500 |
| 18310 | |
| 18311 | # ============================================================================ |
| 18312 | # REAL-TIME SCANNING ENDPOINTS |
| 18313 | # ============================================================================ |
| 18314 | |
| 18315 | def run_arp_scan_localnet(interface='wlan0'): |
| 18316 | """Discover active hosts on the local network. |
| 18317 | |
| 18318 | Two independent sources are merged: the active ``arp-scan`` broadcast |
| 18319 | sweep (authoritative for vendor strings) and the kernel neighbour table |
| 18320 | (catches the hosts the sweep missed). A single sweep misses most live |
| 18321 | hosts on Wi-Fi, and treating that as ground truth is what made every |
| 18322 | target flap to Offline between scans. |
| 18323 | """ |
| 18324 | # --retry/--timeout: one probe per host at the 100ms default loses hosts |
| 18325 | # behind a power-saving Wi-Fi client. --ignoredups keeps duplicate |
| 18326 | # replies from being parsed twice. |
| 18327 | command = ['sudo', 'arp-scan', f'--interface={interface}', '--localnet', |
| 18328 | '--retry=3', '--timeout=500', '--ignoredups'] |
| 18329 | logger.info(f"Running arp-scan localnet: {' '.join(command)}") |
| 18330 | hosts = {} |
| 18331 | try: |
| 18332 | result = subprocess.run(command, capture_output=True, text=True, timeout=30) |
nothing calls this directly
no test coverage detected