-
Notifications
You must be signed in to change notification settings - Fork 1
/
accord_2016_bluetoothsettings.py
73 lines (51 loc) · 2.44 KB
/
accord_2016_bluetoothsettings.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
#!/usr/bin/python
# Python 3 script that reads bluetoothsettings.db "bluetooth_device" table and outputs details to TSV file
# Author: A. Leong (based on data shared by M. Fuentes)
# Tested on Win10x64 running Python 3.9
# bluetoothsettings.db can be found at: \data\com.clarion.bluetooth\databases\bluetoothsettings.db
import argparse
import datetime
import sqlite3
from os import path
version_string = "accord_2016_bluetoothsettings.py v2021-03-23"
def main():
usagetxt = " %(prog)s [-d inputfile -o outputfile]"
parser = argparse.ArgumentParser(description='Reads Honda Accord (2016) bluetoothsettings.db "bluetooth_device" table and outputs details to TSV', usage=usagetxt)
parser.add_argument("-d", dest="database", action="store", required=True, help='SQLite DB filename i.e. bluetoothsettings.db')
parser.add_argument("-o", dest="output", action="store", required=True, help='Output file name for Tab-Separated-Value report')
args = parser.parse_args()
print("Running " + version_string + "\n")
if not args.database or not args.output:
parser.exit("ERROR - Input file or Output file NOT specified")
# Check DB file exists before trying to connect
if path.isfile(args.database):
dbcon = sqlite3.connect(args.database)
else:
print(args.database + " DB file does not exist!")
exit(-1)
query = "SELECT device_bank, device_addr, device_name FROM bluetooth_device ORDER BY device_bank ASC;"
cursor = dbcon.cursor()
cursor.execute(query)
row = cursor.fetchone()
entries = []
while row:
device_bank = str(row[0])
device_addr = row[1]
device_name = row[2]
# store each row returned
entries.append((device_bank, device_addr, device_name))
row = cursor.fetchone()
cursor.close()
dbcon.close()
# Write TSV report
with open(args.output, "w") as outputTSV:
outputTSV.write("device_bank\tdevice_addr\tdevice_name\n")
for entry in entries:
device_bank = entry[0]
device_addr = entry[1]
device_name = entry[2]
outputTSV.write(device_bank + "\t" + device_addr + "\t" + device_name + "\n")
print("Processed/Wrote " + str(len(entries)) + " entries to: " + args.output + "\n")
print("Exiting ...\n")
if __name__ == "__main__":
main()