I have been working on Scapy to sniff the wifi packets & works like a champ. With self interest started to read other supporting feature like bluetooth that supported by Scapy framework
Started to search for few samples but no luck. So i decided to code myself following instruction mentioned in scapy.
sudo hciconfig hci0 up
sudo hciconfig hci0 piscan # Enable the Bluetooth adapter to be discoverable
sudo hcidump -X
snippet:
from scapy.all import *
import sys
# This callback will process Bluetooth packets
def packet_callback(packet):
if packet.haslayer(Bluetooth_HCI_Hdr):
if packet.haslayer(Bluetooth_HCI_Data):
# Check if it's a Probe Request (you might need to inspect the specific packet format for your platform)
if packet[Bluetooth_HCI_Data].opcode == 0x04: # Probe Request opcode
print("Probe Request captured:")
print(packet.show())
# Start sniffing for Bluetooth packets
def start_sniffing(interface):
print(f"Starting Bluetooth sniffing on {interface}...")
sniff(iface=interface, prn=packet_callback, store=0)
# Make sure the script is run with root privileges to access the Bluetooth interface
if __name__ == "__main__":
# You need to specify your Bluetooth interface, e.g., 'hci0' for Linux
interface = "hci0"
start_sniffing(interface)
On running the above code getting an error stating
File "/home/scapy_bluetooth/probe_request.py", line 22, in <module>
start_sniffing(interface)
File "/home/scapy_bluetooth/probe_request.py", line 16, in start_sniffing
sniff(iface=interface, prn=packet_callback, store=0)
File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 1311, in sniff
sniffer._run(*args, **kwargs)
File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 1171, in _run
sniff_sockets[_RL2(iface)(type=ETH_P_ALL, iface=iface,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/scapy/arch/linux.py", line 499, in __init__
set_promisc(self.ins, self.iface)
File "/usr/lib/python3/dist-packages/scapy/arch/linux.py", line 179, in set_promisc
mreq = struct.pack("IHH8s", get_if_index(iff), PACKET_MR_PROMISC, 0, b"")
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/scapy/arch/linux.py", line 399, in get_if_index
return int(struct.unpack("I", get_if(iff, SIOCGIFINDEX)[16:20])[0])
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/scapy/arch/unix.py", line 42, in get_if
return ioctl(sck, cmd, struct.pack("16s16x", iff.encode("utf8")))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 19] No such device
When i used ifconfig hci0 in command line
hci0: error fetching interface information: Device not found
rfkill list bluetooth
1: hci1: Bluetooth
Soft blocked: no
Hard blocked: no
4: hci0: Bluetooth
Soft blocked: no
Hard blocked: no
Not sure, why hci0 is not detected.
thanks for reading.