-
Notifications
You must be signed in to change notification settings - Fork 9
/
BT_Hack_Scan_Process.py
89 lines (74 loc) · 2.08 KB
/
BT_Hack_Scan_Process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/python
import time
import subprocess
import struct
import os
import binascii
import threading
import signal
import socket
from scapy.all import *
from BTLE import *
def main():
output = subprocess.check_output(['bash','-c', "hciconfig hci0 down"])
s = BluetoothUserSocket()
LEsetscanparam(s, "01")
LEsetscan(s, "01", "00")
BD_Addr = []
while not keystop():
try:
data = None
data = s.recv()
data = str(data).encode("hex")
addr = data[14:26]
addr = ":".join(reversed([addr[i:i+2] for i in range(0, len(addr), 2)]))
if data[2:4] == "3e":
if data[10:12] == "04":
if data[36:38] == "08":
data_length = (int(data[34:36],16) - 1)*2
name = data[38:38+data_length].decode("hex")
if addr not in BD_Addr:
print addr + " " + name
BD_Addr.append(addr)
if data[30:32] == "09":
data_length = (int(data[28:30],16) - 1)*2
name = data[32:32+data_length].decode("hex")
if addr not in BD_Addr:
print addr + " " + name
BD_Addr.append(addr)
elif data[10:12] == "00":
length = int(data[34:36],16)*2
if data[38+length:40+length] == "08":
data_length = (int(data[36+length:38+length],16) - 1)*2
name = data[40+length:40+data_length+length].decode("hex")
if addr not in BD_Addr:
print addr + " " + name
BD_Addr.append(addr)
elif data[38+length:40+length] == "09":
data_length = (int(data[36+length:38+length],16) - 1)*2
name = data[40+length:40+data_length+length].decode("hex")
if addr not in BD_Addr:
print addr + " " + name
BD_Addr.append(addr)
else:
if addr not in BD_Addr:
print addr + " " + "Unknown"
BD_Addr.append(addr)
except KeyboardInterrupt:
print "\nExiting"
LEsetscan(s, "00", "00")
disconnect(s)
sys.exit()
return()
def keystop(delay = 0):
return len(select.select([sys.stdin], [], [], delay)[0])
if __name__ == "__main__":
while not keystop():
try:
main()
except KeyboardInterrupt:
print "\n Exiting"
except IndexError:
print "Error: Index"
finally:
sys.exit()