mirror of
https://github.com/smittix/intercept.git
synced 2026-04-24 06:40:00 -07:00
Fix bluetoothctl parsing - add missing imports and improve regex
- Add missing time and re imports in stream function - Improve ANSI escape code stripping (add \x1b[K and \r removal) - Make MAC address regex more explicit - Add debug logging for Device lines 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
16
intercept.py
16
intercept.py
@@ -5698,6 +5698,8 @@ def stream_bt_scan(process, scan_mode):
|
||||
# bluetoothctl scan output - read from pty
|
||||
import os
|
||||
import select
|
||||
import time
|
||||
import re
|
||||
|
||||
master_fd = getattr(process, '_master_fd', None)
|
||||
if not master_fd:
|
||||
@@ -5721,15 +5723,21 @@ def stream_bt_scan(process, scan_mode):
|
||||
line = line.strip()
|
||||
|
||||
# Remove ANSI escape codes
|
||||
import re
|
||||
line = re.sub(r'\x1b\[[0-9;]*m', '', line)
|
||||
line = re.sub(r'\x1b\[\?.*?[a-zA-Z]', '', line)
|
||||
line = re.sub(r'\x1b\[K', '', line) # Clear line escape
|
||||
line = re.sub(r'\r', '', line) # Remove carriage returns
|
||||
|
||||
# Debug: print what we're receiving
|
||||
if line and 'Device' in line:
|
||||
print(f"[BT] bluetoothctl: {line}")
|
||||
|
||||
# Parse [NEW] Device or [CHG] Device lines
|
||||
if 'Device' in line and ':' in line:
|
||||
match = re.search(r'([0-9A-Fa-f:]{17})\s*(.*)', line)
|
||||
# Format: [NEW] Device AA:BB:CC:DD:EE:FF DeviceName
|
||||
if 'Device' in line:
|
||||
match = re.search(r'([0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2})\s*(.*)', line)
|
||||
if match:
|
||||
mac = match.group(1)
|
||||
mac = match.group(1).upper()
|
||||
name = match.group(2).strip()
|
||||
|
||||
device = {
|
||||
|
||||
Reference in New Issue
Block a user