###### tags: `ハッカソン` # 無題 ```shell= sudo apt update sudo apt upgrade sudo apt install python3-pip libglib2.0-dev sudo pip3 install bluepy sudo apt install postfix sudo apt install python3-pandas # インターネットサイト->了解 ``` bluetooth は検出可能にしておく。 ```shell= crontab -e * * * * * sudo /usr/bin/python3 /home/pi/Desktop/blue_scan/scan.py > /home/pi/Desktop/blue_scan/log.txt ``` --- ```shell= ssh pi@raspberrypi.local ssh-keygen -R raspberrypi.local sudo date --set="2021-04-20 10:40:30" ``` ```python= import bluepy scanner = bluepy.btle.Scanner(0) devices = scanner.scan(3) for device in devices: print('======================================================') print('address : %s' % device.addr) print('addrType: %s' % device.addrType) print('RSSI : %s' % device.rssi) print('Adv data:') for (adtype, desc, value) in device.getScanData(): print(' (%3s) %s : %s ' % (adtype, desc, value)) ``` --- ```shell= sudo hciconfig hci0 down && sudo hciconfig hci0 up ``` ```python= data = [date,opening_price,closing_price,Volume] df = pd.read_csv('./log.csv') mycsv = df.sort_values('date') d = pd.Series(data, index=df.columns) mycsv=mycsv.append(data, ignore_index=True) mycsv=mycsv.reset_index(drop=True) mycsv.to_csv('./log.csv') ``` ```python= import bluepy import pandas as pd import datetime scanner = bluepy.btle.Scanner(0) devices = scanner.scan(3) now_t = datetime.datetime.now() count = 0 for device in devices: df_t = now_t.strftime('%Y-%m-%d %H:%M') addr = device.addr rssi = device.rssi count += 1 for (adtype, desc, value) in device.getScanData(): if desc == "Manufacturer": value = value data = pd.DataFrame([[df_t,addr,rssi,value]]) data.to_csv("/home/pi/Desktop/blue_scan/log.csv",index=False,encoding='utf-8', mode='a', header=False) print(str(now_t) + ' : ' + str(count)) ``` ```python= import bluepy scanner = bluepy.btle.Scanner(0) devices = scanner.scan(3) count = 0 for device in devices: if device.rssi count += 1 print(count) ``` ```python= import bluepy import pandas as pd scanner = bluepy.btle.Scanner(0) devices = scanner.scan(3) df = pd.read_csv('./data.csv') for device in devices: print('address : %s' % device.addr) print('addrType: %s' % device.addrType) print('RSSI : %s' % device.rssi) print('Adv data:') for (adtype, desc, value) in device.getScanData(): print(' (%3s) %s : %s ' % (adtype, desc, value)) ``` --- ```python= from scapy.all import * probe_list = [] ap_name = input("Enter the name of access point") def Probe_info(pkt): if pkt.haslayer(Dot11ProbeReq): client_name = pkt.info if client_name == ap_name: if pkt.addr2 not in Probe_info: Print("New Probe request--", client_name) Print("MAC is --", pkt.addr2) Probe_list.append(pkt.addr2) sniff(iface = "mon0", prn = Probe_info) ``` ```python= peripheral = btle.Peripheral(MAC_ADDRESS) for service in peripheral.getServices(): print(f'UUID:{service.uuid}') for characteristic in service.getCharacteristics(): print(f' UUID:{characteristic.uuid}') print(f' ハンドル:{characteristic.getHandle()}') print(f' プロパティ:{characteristic.propertiesToString()}') ```