Skip to main content
Glama

Bluetooth MCP Server

windows_advanced_scanner.cpython-311.pyc47.4 kB
� �=�g�����dZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z m Z ddlmZmZddlmZeje��Zej��dkre�d��Gd�d ��Ze��ZdS) u� Module spécialisé pour la détection avancée d'appareils Bluetooth sous Windows en utilisant diverses méthodes spécifiques à Windows. �N)�Dict�List�Optional�Any)�get_friendly_device_name�normalize_mac_address)�get_device_info�WindowsuRCe module est spécifique à Windows et ne fonctionnera pas sur d'autres systèmesc ���eZdZdZddedeedeeee ffd�Z ddedeedeeee ffd�Z deeee ffd �Z dedeeee ffd �Z dedeeee ffd �Zdedeeee ffd �Zdedeeee ffd �Zdeeee ffd�Zdeee fdeeefddfd�ZdS)�WindowsAdvancedScanneruHScanner avancé pour Windows utilisant plusieurs méthodes de détection�$@N�duration� filter_name�returnc���i} t�d��|���}|D]_}|�P|�d��rF|���|�d�����vr |||d<�`|�|��}|D]_}|�P|�d��rF|���|�d�����vr |||d<�`|�|��}|D]_}|�P|�d��rF|���|�d�����vr |||d<�`|�|��}|D]_}|�P|�d��rF|���|�d�����vr |||d<�`|�|��} | D]_}|�P|�d��rF|���|�d�����vr |||d<�`|� ��} | D]_}|�P|�d��rF|���|�d�����vr |||d<�`t�dt|���d���t|� ����S#t$r8} t�dt| ����d� ��gcYd} ~ Sd} ~ wwxYw) u� Effectue un scan avancé des appareils Bluetooth sous Windows en utilisant multiples méthodes et sources de données. Args: duration: Durée du scan en secondes filter_name: Filtre optionnel sur le nom des appareils Returns: Liste de dictionnaires contenant les informations des appareils détectés u%Démarrage du scan Windows avancé...N�name�iduScan Windows avancé terminé. u! appareil(s) unique(s) trouvé(s)u%Erreur lors du scan Windows avancé: T)�exc_info)�logger�debug�_scan_paired_devices�get�lower�_scan_device_manager_devices�_scan_powershell_devices�_scan_bluetooth_radios�_scan_discoverable_devices�_scan_recent_devices�len�list�values� Exception�error�str) �selfrr� all_devices�paired_devices�device� dm_devices� ps_devices� radio_devices�discoverable_devices�recent_devices�es �DF:\DEV\bluetooth-mcp-server\app\services\windows_advanced_scanner.py�scanzWindowsAdvancedScanner.scans���� �- � �L�L�@� A� A� A�"�6�6�8�8�N�(� 7� 7���&�6�:�:�f�+=�+=�&�+�BS�BS�BU�BU�Y_�Yc�Yc�dj�Yk�Yk�Yq�Yq�Ys�Ys�Bs�Bs�06�K��t� �-���:�:�8�D�D�J�$� 7� 7���&�6�:�:�f�+=�+=�&�+�BS�BS�BU�BU�Y_�Yc�Yc�dj�Yk�Yk�Yq�Yq�Ys�Ys�Bs�Bs�06�K��t� �-���6�6�x�@�@�J�$� 7� 7���&�6�:�:�f�+=�+=�&�+�BS�BS�BU�BU�Y_�Yc�Yc�dj�Yk�Yk�Yq�Yq�Ys�Ys�Bs�Bs�06�K��t� �-��!�7�7��A�A�M�'� 7� 7���&�6�:�:�f�+=�+=�&�+�BS�BS�BU�BU�Y_�Yc�Yc�dj�Yk�Yk�Yq�Yq�Ys�Ys�Bs�Bs�06�K��t� �-��$(�#B�#B�8�#L�#L� �.� 7� 7���&�6�:�:�f�+=�+=�&�+�BS�BS�BU�BU�Y_�Yc�Yc�dj�Yk�Yk�Yq�Yq�Ys�Ys�Bs�Bs�06�K��t� �-��"�6�6�8�8�N�(� 7� 7���&�6�:�:�f�+=�+=�&�+�BS�BS�BU�BU�Y_�Yc�Yc�dj�Yk�Yk�Yq�Yq�Ys�Ys�Bs�Bs�06�K��t� �-�� �L�L�n�3�{�;K�;K�n�n�n� o� o� o�� �*�*�,�,�-�-� -��� � � � �L�L�I��Q���I�I�TX�L� Y� Y� Y��I�I�I�I�I�I����� ���s�L-L2�2 M4�<-M/�)M4�/M4c��HK�tj|j||���d{V��S)u= Version asynchrone du scan Windows avancé. Args: duration: Durée du scan en secondes filter_name: Filtre optionnel sur le nom des appareils Returns: Liste de dictionnaires contenant les informations des appareils détectés N)�asyncio� to_threadr0)r%rrs r/� scan_asyncz!WindowsAdvancedScanner.scan_asyncZs1�����&�t�y�(�K�H�H�H�H�H�H�H�H�H�c���g} t�d��gd�}|D�]C} tjtj|��5}tj|��d}t |��D�]�} tj||���tj|���5}d}dD]&} tj|| ��\}} |rn� #Y�$xYw|sd}�} t���dkr]d� �fd �t dtdt�����d ��D����� ��} d ���} d} tj|d ��\}} d |d��} n#YnxYwd|vp d|vpd|vpd|v}|dks|r(|� | | |digidd|dd|�d| ��d� ��ddd��n #1swxYwY��W#t$r5}t�dt|������Yd}~���d}~wwxYw ddd��n #1swxYwY��#t$r8}t�d|�dt|������Yd}~��=d}~wwxYwt�dt|���d���nA#t$r4}t�dt|������Yd}~nd}~wwxYw|S) u� Récupère la liste des appareils Bluetooth déjà appairés à Windows via le registre Windows. Returns: Liste de dictionnaires contenant les informations des appareils appairés u9Récupération des appareils appairés via le registre...)z<SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devicesz8SYSTEM\CurrentControlSet\Services\BTH\Parameters\Devicesz;SOFTWARE\Microsoft\Windows\CurrentVersion\Bluetooth\DevicesrN)�Name� FriendlyName� DeviceName� DeviceDesczUnknown Paired Device� �:c�*��g|]}�||dz���S���)�.0�i� device_addrs �r/� <listcomp>z?WindowsAdvancedScanner._scan_paired_devices.<locals>.<listcomp>�sB���CG�CG�CG�Z[�;�q�QR�ST�QT�u�CU�CG�CG�CGr5r?z WIN-PAIRED-�Class�0x�08X�TV�Freebox�Box�Bouygtel�����zWindows-PairedzUnknown (Windows Paired)�windows_registry_pairedzRegistry Path: z, Device Class: ) r�addressr�rssi�manufacturer_data� service_uuids� service_data� device_type� company_name� friendly_name� detected_by�raw_infou2Erreur lors de la lecture d'un appareil appairé: u.Erreur lors de l'accès au chemin de registre z: �Récupération terminée: u# appareil(s) appairé(s) trouvé(s)u:Erreur lors de la récupération des appareils appairés: )rr�winreg�OpenKey�HKEY_LOCAL_MACHINE� QueryInfoKey�range�EnumKey� QueryValueExr�join�min�upper�appendr"r$r#)r%�devices�registry_paths� registry_path�key� num_subkeysrB� device_keyr� prop_name�_�formatted_addr� device_id� device_class� class_val�is_special_devicer.rCs @r/rz+WindowsAdvancedScanner._scan_paired_devicesgs������M `� �L�L�T� U� U� U����N� "0�> m�> m� �=m����(A�=�Q�Q�:l�UX�&,�&9�#�&>�&>�q�&A� �!&�{�!3�!3�6l�6l�A�5l�.4�n�S�!�.D�.D� �&,�^�C��%E�%E�/!+��+/�D�5i�%1�%1� �)1�6<�6I�*�V_�6`�6`�G�D�!�/3�-6�05��-6��)1�,0�D����+/�%G�/F��6A�N�'*�;�'7�'7�2�'=�'=�9<���CG�CG�CG�CG�_d�ef�hk�ln�ps�t�qA�qA�iB�iB�DE�`F�`F�CG�CG�CG�:H�:H�:N�:N�:P�:P��0K�k�0K�0K�I�48�L�%-�7=�7J�:�W^�7_�7_� � �1�7K�I�7K�7K�7K� � ��%-�(,�����9=�� �9A� �UY�HY�9A�]b�fj�]j�9A�nx�}A�oA�$5�(,�/F�'F�'F�J[�'F�(/���2;�7E�48�47�AC�=?�<>�;K�<V�=A�;T�8w�-�8w�8w�iu�8w�8w� 8*� 8*� )+� )+� )+�E/!+�/!+�/!+�/!+�/!+�/!+�/!+�/!+�/!+�/!+�/!+����/!+�/!+�/!+�/!+���`$-�l�l�l� &� � �-j�be�fg�bh�bh�-j�-j� k� k� k� k� k� k� k� k�����l����k6l� :l�:l�:l�:l�:l�:l�:l�:l�:l�:l�:l����:l�:l�:l�:l���v!�m�m�m��L�L�!k�R_�!k�!k�cf�gh�ci�ci�!k�!k�l�l�l�l�l�l�l�l�����m���� �L�L�g�c�'�l�l�g�g�g� h� h� h� h��� `� `� `� �L�L�^�VY�Z[�V\�V\�^�^� _� _� _� _� _� _� _� _����� `�����s��#J�H%�-H�6*G � F< �(C �F< �C �BF< � E)�(F< �)E- �+AF< �0 G �<G �G �G �G �H� H �*H �=H�H �H� H%�H �H%�H � H%�#J�% I'�/-I"�J�"I'�'.J� K� *K�Kc��g} t�d��gd�}tj|dd|d���}d}|j���D�]�}t j||��}|�rw|�d��� ��}|�d��� ��} |�d ��� ��} |�d ��� ��} | � d d ��� d d ��} d| ��} t j d| ��}|r|�d��n | dd�}|dkrdnd}d}d| vrdd| d�}n d| vrdd| d�}nd| vrdd| d�}n d| vrdd| d�}| || |igid | ��|r|d!nd"| d#d$| �d%| �d&|��|dkd'� }|� |�����t�d(t|���d)���nA#t$r4}t�d*t!|������Yd}~nd}~wwxYw|S)+uP Récupère les appareils Bluetooth depuis le Gestionnaire de périphériques via PowerShell. Args: duration: Durée maximale pour l'exécution de la commande Returns: Liste de dictionnaires contenant les informations des appareils du Device Manager uIRécupération des appareils depuis le Gestionnaire de périphériques...)� powershell� -NoProfile�-Commandu� $OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 try { # Obtenir tous les appareils Bluetooth, Media et autres catégories pertinentes Get-PnpDevice -Class Bluetooth,Media,AudioEndpoint,HIDClass | Where-Object { $_.Status -eq 'OK' } | ForEach-Object { Write-Output ("DM-DEVICE: " + $_.FriendlyName + " | ID: " + $_.DeviceID + " | Class: " + $_.Class) } # Recherche spécifique des TV, Freebox et autres appareils spéciaux Get-PnpDevice | Where-Object { ($_.FriendlyName -like "*TV*" -or $_.FriendlyName -like "*Freebox*" -or $_.FriendlyName -like "*Box*" -or $_.FriendlyName -like "*Bouygtel*") -and $_.Status -eq 'OK' } | ForEach-Object { Write-Output ("SPECIAL-DEVICE: " + $_.FriendlyName + " | ID: " + $_.DeviceID + " | Class: " + $_.Class) } } catch { Write-Output "Error: $_" } T�utf-8��capture_output�text�timeout�encodingz4(DM|SPECIAL)-DEVICE: (.*) \| ID: (.*) \| Class: (.*)�r?���&�-�\zWIN-DM-�'([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})rN��SPECIAL�����rLrHzTV Manufacturer)�companyrSrUrI� Freebox SArJz ISP Providerz Set-top BoxrK�Bouygues Telecom�Windows-r�zUnknown (Windows)�windows_device_managerzClass: �, ID: �, Type: � rrNrrOrPrQrRrSrTrUrVrWrprXu? appareil(s) trouvé(s) dans le Gestionnaire de périphériquesu8Erreur lors du scan du Gestionnaire de périphériques: )rr� subprocess�run�stdout� splitlines�re�match�group�strip�replace�searchrcrr"r#r$)r%rrd�powershell_cmd�result�device_pattern�liner�rSrrmrn�clean_device_id� unique_id� mac_matchrNrO� device_infor(r.s r/rz3WindowsAdvancedScanner._scan_device_manager_devices�s����a ^� �L�L�d� e� e� e����N�: �^��#�� � � ���F�U�N�� �0�0�2�2�0 +�0 +������6�6���.+�"'�+�+�a�.�.�"6�"6�"8�"8�K� �;�;�q�>�>�/�/�1�1�D� %� � �A��� 4� 4� 6� 6�I�#(�;�;�q�>�>�#7�#7�#9�#9�L�'0�&7�&7��S�&A�&A�&I�&I�$�PS�&T�&T�O� ;�/� ;� ;�I�!#� �*T�V_� `� `�I�4=�Q�i�o�o�a�0�0�0�9�S�b�S�>�G�#.��":�":�3�3��D�#'�K��t�|�|�2C�TX�ko�&p�&p� � �"�d�*�*�2>�y�ko�&p�&p� � ��$���2@�Q^�qu�&v�&v� � �#�t�+�+�2D�Ub�uy�&z�&z� �(�#*� $� $�-/�)+�(*�'@�,�'@�'@�BM�(f� �I�(>�(>�Sf�)-�'?�$b�l�$b�$b�)�$b�$b�U`�$b�$b�-8�I�-E���F� �N�N�6�*�*�*�� �L�L�D�c�'�l�l�D�D�D� E� E� E� E��� ^� ^� ^� �L�L�\�TW�XY�TZ�TZ�\�\� ]� ]� ]� ]� ]� ]� ]� ]����� ^�����s�HH� I� *I�Ic�B�g} t�d��gd�}tj|dd|d���}d}d}d}i}|j���D�]'} t j|| ��} | �rg|r-|�||��|� |��i}| � d ��� ��} | � d ��� ��} | � d ��� ��} | � d ��� ��}| r| d krd}��| � dd��� dd��}d|��}t j d| ��}|r|� d��n |dd�}| dkrdnd}||| |igid|��d| dd|�d| �d| ��| dkd� }���| dkr3|r/|�||��|� |��d}i}���|rjt j|| ��}|rS|� d ��� ��}|� d ��� ��}|||<��)|r+|�||��|� |��t�d t|���d!���nA#t$r4}t�d"t#|������Yd}~nd}~wwxYw|S)#uA Récupère les appareils Bluetooth via PowerShell en utilisant les API spécifiques à Windows. Args: duration: Durée maximale pour l'exécution de la commande Returns: Liste de dictionnaires contenant les informations des appareils u.Récupération des appareils via PowerShell...)rrrsrtu� $OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 try { # Essayer de charger les assemblies Windows Runtime Add-Type -AssemblyName System.Runtime.WindowsRuntime # Fonction pour attendre les tâches asynchrones function Await($WinRtTask, $ResultType) { $asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | Where-Object { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 })[0].MakeGenericMethod($ResultType) $netTask = $asTask.Invoke($null, @($WinRtTask)) $netTask.Wait(-1) | Out-Null $netTask.Result } # Charger les namespaces nécessaires [Windows.Devices.Enumeration.DeviceInformation,Windows.Devices.Enumeration,ContentType=WindowsRuntime] | Out-Null # 1. Recherche d'appareils Bluetooth avec des filtres plus larges $selectors = @( # Sélecteur standard Bluetooth [Windows.Devices.Bluetooth.BluetoothDevice]::GetDeviceSelector(), # Sélecteur pour les radios Bluetooth [Windows.Devices.Radios.Radio]::GetRadiosAsync(), # Sélecteur pour les appareils audio [Windows.Devices.Enumeration.DeviceClass]::AudioRender, # Sélecteur pour les appareils vidéo [Windows.Devices.Enumeration.DeviceClass]::VideoDisplay ) foreach ($selector in $selectors) { try { $devicesAsync = [Windows.Devices.Enumeration.DeviceInformation]::FindAllAsync($selector) $foundDevices = Await $devicesAsync ([System.Collections.Generic.IReadOnlyList[Windows.Devices.Enumeration.DeviceInformation]]) foreach ($device in $foundDevices) { Write-Output ("PS-DEVICE: " + $device.Name + " | ID: " + $device.Id + " | Kind: " + $device.Kind) # Ajouter les propriétés utiles $device.Properties | ForEach-Object { foreach ($prop in $_.Keys) { Write-Output ("PROP: " + $prop + " = " + $device.Properties[$prop]) } } Write-Output ("---") } } catch { Write-Output ("Selector Error: $_") } } # 2. Recherche spécifique des TV, Freebox et autres appareils spéciaux try { $specialSelector = "System.Devices.DevObjectType:=5 AND System.Devices.Aep.ProtocolId:="{e0cbf06c-cd8b-4647-bb8a-263b43f0f974}"" $specialDevicesAsync = [Windows.Devices.Enumeration.DeviceInformation]::FindAllAsync($specialSelector, $null) $specialDevices = Await $specialDevicesAsync ([System.Collections.Generic.IReadOnlyList[Windows.Devices.Enumeration.DeviceInformation]]) foreach ($device in $specialDevices) { Write-Output ("SPECIAL-PS-DEVICE: " + $device.Name + " | ID: " + $device.Id + " | Kind: " + $device.Kind) # Ajouter les propriétés utiles $device.Properties | ForEach-Object { foreach ($prop in $_.Keys) { Write-Output ("PROP: " + $prop + " = " + $device.Properties[$prop]) } } Write-Output ("---") } } catch { Write-Output ("Special Selector Error: $_") } } catch { Write-Output "General Error: $_" } Trurvz6(PS|SPECIAL-PS)-DEVICE: (.*) \| ID: (.*) \| Kind: (.*)zPROP: (.*) = (.*)Nr{r?r|r}��#rr�zWIN-PS-r�rr�z SPECIAL-PSr�rLr�zUnknown (Windows PowerShell)�windows_powershellzKind: r�r�r�z---u%Récupération PowerShell terminée: � appareil(s) trouvé(s)z Erreur lors du scan PowerShell: )rrr�r�r�r�r�r��_enrich_device_with_propertiesrcr�r�r�r�rr"r#r$)r%rrdr�r�r�� prop_pattern�current_device� propertiesr�� device_matchrSrrm� device_kindr�r�r�rNrO� prop_matchrj� prop_valuer.s r/rz/WindowsAdvancedScanner._scan_powershell_devices4s�����p F� �L�L�I� J� J� J�O�O�O�N�d �^��#�� � � ���F�W�N�/�L�!�N��J�� �0�0�2�2�@ ;�@ ;��!�x���=�=� ��>;�%�(��;�;�N�J�W�W�W����~�6�6�6�%'� �".�"4�"4�Q�"7�"7�"=�"=�"?�"?�K�'�-�-�a�0�0�6�6�8�8�D� ,� 2� 2�1� 5� 5� ;� ;� =� =�I�".�"4�"4�Q�"7�"7�"=�"=�"?�"?�K� �!�4�2�:�:�)-�� �'0�&7�&7��S�&A�&A�&I�&I�$�PS�&T�&T�O� ;�/� ;� ;�I�!#� �*T�V_� `� `�I�4=�Q�i�o�o�a�0�0�0�9�S�b�S�>�G�#.��"=�"=�3�3�3�D�(�#*� $� $�-/�)+�(*�'?�+�'?�'?�(F�)-�';�$`�[�$`�$`� �$`�$`�S^�$`�$`�-8�L�-H�&�&�N�N� �U�]�]�%�(��;�;�N�J�W�W�W����~�6�6�6�)-��%'� ��#�;�!#��,��!=�!=�J�!�;�$.�$4�$4�Q�$7�$7�$=�$=�$?�$?� �%/�%5�%5�a�%8�%8�%>�%>�%@�%@� �0:� �9�-��� /��3�3�N�J�O�O�O����~�.�.�.� �L�L�f��W���f�f�f� g� g� g� g��� F� F� F� �L�L�D�C��F�F�D�D� E� E� E� E� E� E� E� E����� F�����s�KK� L�(*L�Lc�(�g} t�d��gd�}tj|dd|d���}d}d}|j���D�]�}t j||��}t j||��} |r�|�d��� ��} |�d ��� ��} |�d ��� ��} | � d d ��� d d ��} d| ��}| dkr1|� ||dd�| digidd| dd| �d| ��dd� ���� | r�| �d��� ��} | �d ��� ��}| �d ��� ��} d|� dd ����}| dkr)|� ||| digidd| dd| �d|��dd� �����t�dt|���d ���nA#t$r4}t�d!t|������Yd}~nd}~wwxYw|S)"u Détecte les radios Bluetooth disponibles sur le système. Args: duration: Durée maximale pour l'exécution de la commande Returns: Liste de dictionnaires contenant les informations des radios Bluetooth z!Recherche des radios Bluetooth...)rrrsrta� $OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 try { # Essayer d'utiliser Get-PnpDevice pour les radios Get-PnpDevice -Class Bluetooth,Net | Where-Object { $_.FriendlyName -like "*Radio*" -or $_.FriendlyName -like "*Bluetooth*" -or $_.FriendlyName -like "*Wireless*" } | ForEach-Object { Write-Output ("RADIO: " + $_.FriendlyName + " | ID: " + $_.DeviceID + " | Status: " + $_.Status) } # Utiliser Get-NetAdapter pour les adaptateurs Bluetooth Get-NetAdapter | Where-Object { $_.Name -like "*Bluetooth*" -or $_.InterfaceDescription -like "*Bluetooth*" } | ForEach-Object { Write-Output ("BT-ADAPTER: " + $_.Name + " | MAC: " + $_.MacAddress + " | Status: " + $_.Status) } } catch { Write-Output "Error: $_" } Trurvz'RADIO: (.*) \| ID: (.*) \| Status: (.*)z-BT-ADAPTER: (.*) \| MAC: (.*) \| Status: (.*)r{r?r|r~rr�z WIN-RADIO-�OKNr�i����z Windows-RadiozLocal Bluetooth Adapter� windows_radiozStatus: r�) rrNrrOrPrQrRrSrTrUrVrW�is_local_adapterzWIN-BT-ADAPTER-r<�UpzWindows-BT-Adapter�windows_bt_adapterz, MAC: u Recherche des radios terminée: u radio(s) trouvée(s)z2Erreur lors de la recherche des radios Bluetooth: )rrr�r�r�r�r�r�r�r�r�rcrr"r#r$)r%rrdr�r�� radio_pattern�adapter_patternr�� radio_match� adapter_matchrrm�statusr�r�� mac_addressr.s r/rz-WindowsAdvancedScanner._scan_bluetooth_radios�s����j X� �L�L�<� =� =� =����N�< �^��#�� � � ���F�G�M�N�O�� �0�0�2�2�7 �7 �� �h�}�d�;�;� � "���$� ?� ?� ��3�&�,�,�Q�/�/�5�5�7�7�D� +� 1� 1�!� 4� 4� :� :� <� <�I�(�.�.�q�1�1�7�7�9�9�F�'0�&7�&7��S�&A�&A�&I�&I�$�PS�&T�&T�O� >�_� >� >�I���~�~����"+�'0��"��~�$(�$'�13�-/�,.�+:�,E�-1�+:�(L�6�(L�(L��(L�(L�04�(�(����� #��(�.�.�q�1�1�7�7�9�9�D�"/�"5�"5�a�"8�"8�">�">�"@�"@�K�*�0�0��3�3�9�9�;�;�F�!R�+�2E�2E�c�3�2O�2O� Q� Q�I���~�~����"+�'2�$(�$'�13�-/�,.�+?�,E�-1�+?�(O�6�(O�(O�+�(O�(O�04�(�(����� �L�L�_�C��L�L�_�_�_� `� `� `� `��� X� X� X� �L�L�V�c�RS�f�f�V�V� W� W� W� W� W� W� W� W����� X�����s�I I� J�*J � Jc�4�g} t�d��dddddddd �d |�d �g}tj|d d |d zd���}d}d}|j���D�]�}t j||��}t j||��} |r�|�d��� ��} |�d��� ��} |�d��� ��} t|�d��� ����} | }| r/| dkr)|� || | | igidd| dd| �d| ��d d� ���� | r�| �d��� ��} | �d��� ��} | �d��� ��� ��dk}| }|� || | digidd | d!d"|��|d#� �����t�d$t|���d%���nA#t$r4}t�d&t!|������Yd'}~nd'}~wwxYw|S)(uA Recherche des appareils Bluetooth en mode découvrable à l'aide d'une commande PowerShell spécifique. Args: duration: Durée du scan en secondes Returns: Liste de dictionnaires contenant les informations des appareils découvrables u2Recherche des appareils Bluetooth découvrables...rrrsz-ExecutionPolicy�Bypassrtu $OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 try { # Essayer d'utiliser l'interface Windows.Devices.Bluetooth Add-Type -AssemblyName System.Runtime.WindowsRuntime $asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | Where-Object { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0] Function AwaitOperation($WinRtTask, $ResultType) { $asTask = $asTaskGeneric.MakeGenericMethod($ResultType) $netTask = $asTask.Invoke($null, @($WinRtTask)) $netTask.Wait(-1) | Out-Null return $netTask.Result } # Chargement des classes nécessaires [Windows.Devices.Enumeration.DeviceInformation,Windows.Devices.Enumeration,ContentType=WindowsRuntime] | Out-Null [Windows.Devices.Bluetooth.BluetoothDevice,Windows.Devices.Bluetooth,ContentType=WindowsRuntime] | Out-Null [Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementWatcher,Windows.Devices.Bluetooth.Advertisement,ContentType=WindowsRuntime] | Out-Null # Initialiser et configurer le watcher BLE $bleWatcher = New-Object Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementWatcher $bleWatcher.ScanningMode = 1 # Active # Liste pour stocker les appareils détectés $devices = @{} # Gestionnaire d'événements pour les publicités reçues Register-ObjectEvent -InputObject $bleWatcher -EventName Received -Action { $device = $Event.SourceArgs.BluetoothAddress $addr = ("r�X12u" -f $device) -replace '(..)(..)(..)(..)(..)(..)', '$6:$5:$4:$3:$2:$1' $rssi = $Event.SourceArgs.RawSignalStrengthInDBm if (-not $devices.ContainsKey($addr)) { $devices[$addr] = @{ "Address" = $addr; "RSSI" = $rssi; "Name" = ""; "IsConnectable" = $Event.SourceArgs.IsConnectable; "Timestamp" = Get-Date; } # Essayer d'obtenir plus d'informations sur l'appareil try { $deviceInfoAsync = [Windows.Devices.Bluetooth.BluetoothLEDevice]::FromBluetoothAddressAsync($device) $deviceInfo = AwaitOperation $deviceInfoAsync ([Windows.Devices.Bluetooth.BluetoothLEDevice]) if ($deviceInfo -ne $null) { $devices[$addr]["Name"] = $deviceInfo.Name $devices[$addr]["DeviceInfo"] = $deviceInfo # Écrire les informations de l'appareil $name = if ([string]::IsNullOrEmpty($deviceInfo.Name)) { "Unknown" } else { $deviceInfo.Name } Write-Output ("DISCOVERABLE: " + $name + " | Address: " + $addr + " | RSSI: " + $rssi) } } catch { # Ignorer les erreurs de connexion } } } # Démarrer le scan $bleWatcher.Start() # Attendre pendant la durée spécifiée Start-Sleep -Seconds u, # Arrêter le scan $bleWatcher.Stop() # Afficher tous les appareils découverts foreach ($addr in $devices.Keys) { $name = if ([string]::IsNullOrEmpty($devices[$addr].Name)) { "Unknown" } else { $devices[$addr].Name } Write-Output ("DISCOVERED: " + $name + " | Address: " + $addr + " | RSSI: " + $devices[$addr].RSSI) } # Recherche des appareils Bluetooth classiques # Utiliser BluetoothClient si disponible try { Add-Type -Path "$env:SystemRoot\System32\bthprops.cpl" -ErrorAction Stop $discoverer = New-Object -TypeName "Microsoft.Bluetooth.BluetoothClient" $discDevices = $discoverer.DiscoverDevices(30) foreach ($device in $discDevices) { Write-Output ("BT-CLASSIC: " + $device.DeviceName + " | Address: " + $device.DeviceAddress + " | Authenticated: " + $device.Authenticated) } } catch { Write-Output ("BluetoothClient not available: " + $_) } } catch { Write-Output "Error during discovery: $_" Write-Output $_.ScriptStackTrace } T�rurvz>(DISCOVERABLE|DISCOVERED): (.*) \| Address: (.*) \| RSSI: (.*)z8BT-CLASSIC: (.*) \| Address: (.*) \| Authenticated: (.*)r{r?r|r}�UnknownzWindows-Discoverable-BLEzUnknown (Discoverable)�windows_discoverablezType: z, RSSI: ) rrNrrOrPrQrRrSrTrUrVrW�is_discoverable�truerLzWindows-ClassiczUnknown (Classic)�windows_classiczAuthenticated: ) rrNrrOrPrQrRrSrTrUrVrW�is_authenticatedu1Recherche des appareils découvrables terminée: r�u9Erreur lors de la recherche des appareils découvrables: N)rrr�r�r�r�r�r�r�r��intrcrrr"r#r$)r%rrdr�r��discoverable_pattern�classic_patternr��discoverable_match� classic_matchrSrrNrOr�� authenticatedr.s r/rz1WindowsAdvancedScanner._scan_discoverable_devicesosE����r _� �L�L�M� N� N� N���"�H��^�:$%�;^�^�^�@+3�A^�^�^� d�N�N �^��#�� �1� � � ���F�$e� �Y�O�� �0�0�2�2�6 �6 ��%'�X�.B�D�%I�%I�"� "���$� ?� ?� �%�2�"4�":�":�1�"=�"=�"C�"C�"E�"E�K�-�3�3�A�6�6�<�<�>�>�D�0�6�6�q�9�9�?�?�A�A�G��1�7�7��:�:�@�@�B�B�C�C�D�!(�I���� � 1� 1����"+�'.�$(�$(�13�-/�,.�+E�,D�-1�+A�(L��(L�(L�d�(L�(L�/3�(�(����� #��(�.�.�q�1�1�7�7�9�9�D�+�1�1�!�4�4�:�:�<�<�G�$1�$7�$7��$:�$:�$@�$@�$B�$B�$H�$H�$J�$J�f�$T�M�!(�I��N�N�'�#*� $� #�-/�)+�(*�'8�(;�)-�'8�$E�m�$E�$E�,9�$�$����� �L�L�r�S�QX�\�\�r�r�r� s� s� s� s��� _� _� _� �L�L�]�UX�YZ�U[�U[�]�]� ^� ^� ^� ^� ^� ^� ^� ^����� _�����s�II� J�!*J�Jc�$� �g} t�d��gd�}gd�}tj|dddd���}d}|j���D�]F}t j||��}|�r+|�d ��� ��}|�d ��� ��� |�d ��� ��} � } t� ��d krvtd �� D����r]d� � fd�tdtd t� ����d ��D�������} d� ��} |�| | |digidd|dd| ��dd� ����Ht�dt|���d���nA#t"$r4} t�dt'| ������Yd} ~ nd} ~ wwxYw|S)u� Recherche des appareils Bluetooth récemment connectés via le registre Windows. Returns: Liste de dictionnaires contenant les informations des appareils récents u0Recherche des appareils récemment connectés...)zSHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\RenderzMHKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Bluetooth\DeviceszEHKEY_CURRENT_USER\Software\Microsoft\WindowsNT\CurrentVersion\EMDMgmt)rrrsrtu $OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 function Get-RegistryDevices { param ( [string]$Path ) try { # Vérifier si le chemin existe if (Test-Path $Path) { # Obtenir toutes les sous-clés $subkeys = Get-ChildItem -Path $Path -ErrorAction SilentlyContinue foreach ($key in $subkeys) { try { # Lire les valeurs de la clé $values = Get-ItemProperty -Path $key.PSPath -ErrorAction SilentlyContinue # Vérifier s'il y a des propriétés intéressantes $deviceName = $null $deviceAddr = $null if ($values.FriendlyName) { $deviceName = $values.FriendlyName } elseif ($values.DeviceName) { $deviceName = $values.DeviceName } elseif ($values.Name) { $deviceName = $values.Name } elseif ($values.DisplayName) { $deviceName = $values.DisplayName } # Essayer de trouver une adresse if ($values.BluetoothAddress) { $deviceAddr = $values.BluetoothAddress } elseif ($values.Address) { $deviceAddr = $values.Address } elseif ($key.Name -match "([0-9A-Fa-f]{12})$") { $deviceAddr = $matches[1] } # Si nous avons un nom, ajouter l'appareil if ($deviceName -and ($deviceName -like "*TV*" -or $deviceName -like "*Freebox*" -or $deviceName -like "*Box*" -or $deviceName -like "*Bouygtel*")) { $keyPath = $key.Name -replace "HKEY_LOCAL_MACHINE", "HKLM:" -replace "HKEY_CURRENT_USER", "HKCU:" Write-Output ("RECENT: " + $deviceName + " | ID: " + ($deviceAddr -or $key.PSChildName) + " | Path: " + $keyPath) } # Récursivement chercher dans les sous-clés Get-RegistryDevices -Path $key.PSPath } catch { # Ignorer les erreurs pour cette clé } } } } catch { Write-Output "Error scanning path $Path : $_" } } # Parcourir tous les chemins du registre foreach ($path in @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Bluetooth\Devices', 'HKCU:\Software\Microsoft\WindowsNT\CurrentVersion\EMDMgmt')) { Get-RegistryDevices -Path $path } T� rurvz&RECENT: (.*) \| ID: (.*) \| Path: (.*)r{r?r|r;c3�K�|]}|dvV�� dS)�0123456789ABCDEFabcdefNr@)rA�cs r/� <genexpr>z>WindowsAdvancedScanner._scan_recent_devices.<locals>.<genexpr>�s)����3e�3e�VW�A�9Q�4Q�3e�3e�3e�3e�3e�3er5r<c�*��g|]}�||dz���Sr>r@)rArBrms �r/rDz?WindowsAdvancedScanner._scan_recent_devices.<locals>.<listcomp>�s&���+k�+k�+k��I�a��!��e�,<�+k�+k�+kr5rz WIN-RECENT-i����zWindows-RecentzUnknown (Recent)�windows_recentzPath: ) rrNrrOrPrQrRrSrTrUrVrW� is_recentu,Recherche des appareils récents terminée: r�u4Erreur lors de la recherche des appareils récents: N)rrr�r�r�r�r�r�r�r�r�allr`r]rarbrcr"r#r$)r%rdrer�r��recent_patternr�r�r�reg_pathrNr�r.rms @r/rz+WindowsAdvancedScanner._scan_recent_devices2sq�����D Z� �L�L�K� L� L� L����N�E�E�E�N�P �^��#��� � ���F�G�N�� �0�0�2�2� � ������6�6���� �;�;�q�>�>�/�/�1�1�D� %� � �A��� 4� 4� 6� 6�I�$�{�{�1�~�~�3�3�5�5�H�(�G��9�~�~��+�+��3e�3e�[d�3e�3e�3e�0e�0e�+�"%�(�(�+k�+k�+k�+k�e�A�s�SU�WZ�[d�We�We�Of�Of�hi�Fj�Fj�+k�+k�+k�"l�"l�"r�"r�"t�"t��!:�i� 9� 9�I��N�N�'�#*� $� #�-/�)+�(*�'7�(:�)-�'7�$7�X�$7�$7�%)�$�$����� �L�L�m��G� � �m�m�m� n� n� n� n��� Z� Z� Z� �L�L�X�PS�TU�PV�PV�X�X� Y� Y� Y� Y� Y� Y� Y� Y����� Z�����s�G G� H �*H�H r(r�c���d�vr �d|d<d�vr �d|d<d�vr �d|d<t�fd�dD����r�d |d <d t���vsd t���vrd |d <dt���vrd|d<dSdSdt���vr d|d <d|d<dSdt���vrd|d <d|d<dSdSdS)u� Enrichit un appareil avec des propriétés supplémentaires. Args: device: L'appareil à enrichir properties: Les propriétés à ajouter zSystem.Devices.ModelName�modelzSystem.Devices.ManufacturerrTzSystem.Devices.Category�categoryc3�:�K�|]}|t���vV��dS)N)r$)rA�keywordr�s �r/r�zHWindowsAdvancedScanner._enrich_device_with_properties.<locals>.<genexpr>�s.�����n�n�g�w�#�j�/�/�)�n�n�n�n�n�nr5)rHrIrJrK� TéléviseurTrprHr�rS�SamsungzSamsung Electronics Co. Ltd.rIr�rKr�N)�anyr$)r%r(r�s `r/r�z5WindowsAdvancedScanner._enrich_device_with_properties�sF��� &�� 3� 3�(�)C�D�F�7�O� (�J� 6� 6�%/�0M�%N�F�>� "� $� � 2� 2�!+�,E�!F�F�:� � �n�n�n�n�9m�n�n�n� n� n� <�*.�F�&� '��s�:���&�&�.�C� �O�O�*K�*K�(,��}�%���J���/�/�-K�F�>�*�*�*�0�/��c�*�o�o�-�-�(1��}�%�)5��~�&�&�&��s�:���.�.�(2��}�%�);��~�&�&�&� <� <�/�.r5)r N)�__name__� __module__� __qualname__�__doc__�floatrr$rrrr0r4rrrrrrr�r@r5r/r r s ������R�R�<�<�U�<��� �<�QU�VZ�[^�`c�[c�Vd�Qe�<�<�<�<�| I� I�� I�H�S�M� I�]a�bf�gj�lo�go�bp�]q� I� I� I� I�Y�d�4��S��>�&:�Y�Y�Y�Y�vp�U�p�t�D��c��N�?S�p�p�p�p�d���4��S�#�X��;O�����Bx�u�x��d�3��8�n�9M�x�x�x�x�tA�5�A�T�$�s�C�x�.�=Q�A�A�A�A�FP�d�4��S��>�&:�P�P�P�P�d <�T�#�s�(�^� <�QU�VY�[^�V^�Q_� <�dh� <� <� <� <� <� <r5r )r��logging�platformr�r�r2rY�time�os�typingrrrr�app.utils.bluetooth_utilsrr�app.data.mac_prefixesr � getLoggerr�r�system�warningr �windows_advanced_scannerr@r5r/�<module>r�s0���������������� � � � ����� � � � � � � � � � � � �,�,�,�,�,�,�,�,�,�,�,�,�U�U�U�U�U�U�U�U�1�1�1�1�1�1� �� �8� $� $���8�?��� �!�!� �N�N�g�h�h�h�K<�K<�K<�K<�K<�K<�K<�K<�\2�1�3�3���r5

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Hypijump31/bluetooth-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server