If you want to know the bluetooth device you want to connect to is alive or not, i.e. whether that device’s Bluetooth is ON or not and whether it can respond to our other request like enquiry for information etc.
For this l2ping helps us. L2ping sends a L2CAP echo request to the Bluetooth MAC address bd_addr given in dotted hex notation.
For the very first time, we need to know the BT_ADDR or BT MAC of the device whose status we want to check. We can know the BT MAC using following command,
$ sudo hcitool scan
Scanning ...
6C:C4:D5:6C:C5:BC Nokia 7 plus
Now, lets see if the device is UP or NOT, this command is very similar to network ping.
$ sudo l2ping 6C:C4:D5:6C:C5:BC
Ping: 6C:C4:D5:6C:C5:BC from 70:1A:04:59:69:04 (data size 44) ...
44 bytes from 6C:C4:D5:6C:C5:BC id 0 time 5.93ms
44 bytes from 6C:C4:D5:6C:C5:BC id 1 time 8.76ms
Now, lets see how the command responds when the Bluetooth is OFF
$ sudo l2ping 6C:C4:D5:6C:C5:BC
Can't connect: Host is down