Skip to content

Commit cf194de

Browse files
committed
add bluetooth scanner tutorial
1 parent 676c674 commit cf194de

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
5555
- [How to Crack the Affine Cipher in Python](https://thepythoncode.com/article/how-to-crack-the-affine-cipher-in-python). ([code](ethical-hacking/crack-affine-cipher))
5656
- [How to Implement the Vigenère Cipher in Python](https://thepythoncode.com/article/implementing-the-vigenere-cipher-in-python). ([code](ethical-hacking/implement-vigenere-cipher))
5757
- [How to Generate Fake User Data in Python](https://thepythoncode.com/article/generate-fake-user-data-in-python). ([code](ethical-hacking/fake-user-data-generator))
58+
- [Bluetooth Device Scanning in Python](https://thepythoncode.com/article/build-a-bluetooth-scanner-in-python). ([code](ethical-hacking/bluetooth-scanner))
5859

5960
- ### [Machine Learning](https://www.thepythoncode.com/topic/machine-learning)
6061
- ### [Natural Language Processing](https://www.thepythoncode.com/topic/nlp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [Bluetooth Device Scanning in Python](https://thepythoncode.com/article/build-a-bluetooth-scanner-in-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Import bluetooth from the PyBluez module.
2+
import bluetooth
3+
4+
def scan_bluetooth_devices():
5+
try:
6+
# Discover Bluetooth devices with names and classes.
7+
discovered_devices = bluetooth.discover_devices(lookup_names=True, lookup_class=True)
8+
9+
# Display information about the scanning process.
10+
print('[!] Scanning for active devices...')
11+
print(f"[!] Found {len(discovered_devices)} Devices\n")
12+
13+
# Iterate through discovered devices and print their details.
14+
for addr, name, device_class in discovered_devices:
15+
print(f'[+] Name: {name}')
16+
print(f'[+] Address: {addr}')
17+
print(f'[+] Device Class: {device_class}\n')
18+
19+
except Exception as e:
20+
# Handle and display any exceptions that occur during device discovery.
21+
print(f"[ERROR] An error occurred: {e}")
22+
23+
24+
# Call the Bluetooth device scanning function when the script is run
25+
scan_bluetooth_devices()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pybluez2

0 commit comments

Comments
 (0)