Amir Pournasserian
Published © MIT

Wi-Fi Device Scanner w/ Raspberry Pi

Keep track of your phone, tablet, laptop, and other wireless devices using a Raspberry Pi!

IntermediateFull instructions provided2 hours8,767
Wi-Fi Device Scanner w/ Raspberry Pi

Things used in this project

Story

Read more

Code

wireless_device_scanner

Python
from scapy.all import *
import json
import threading
import http.client

# Configuration section
UBEAC_URL = 'hub.ubeac.io'
GATEWAY_URL = 'http://INSERT GATEWAY URL HERE'
DEVICE_FRIENDLY_NAME = 'RPi detector #'
SENT_INTERVAL = 10 # Sent data interval in second

sensors_dbm = []

check_devices = set()
devices = {"00:00:00:00:00:00" : "DEVICE",
            "00:00:00:00:00:00" : "DEVICE",
            "00:00:00:00:00:00" : "DEVICE"}
            
def get_sensor(id, value, type=None, unit=None, prefix=None, dt=None):
    sensor = {
        'id': id,
        'data': value
    }
    return sensor

def PacketHandler(pkt):
    if pkt.haslayer(Dot11):
        dot11_layer = pkt.getlayer(Dot11)
        if dot11_layer.addr2 and (dot11_layer.addr2 in devices) and (dot11_layer.addr2 not in check_devices):
            check_devices.add(dot11_layer.addr2)
            sensors_dbm.append(get_sensor(devices[dot11_layer.addr2], {"dBm Signal" : pkt[RadioTap].dBm_AntSignal}))
                
def main():
    threading.Timer(SENT_INTERVAL, main).start()
    sniff(iface = "mon0", prn = PacketHandler, timeout = SENT_INTERVAL)
    device = [{
        'id': DEVICE_FRIENDLY_NAME,
        'sensors': sensors_dbm
    }]
    connection = http.client.HTTPSConnection(UBEAC_URL)
    connection.request('POST', GATEWAY_URL, json.dumps(device))
    response = connection.getresponse()
    print(response.read().decode())
    sensors_dbm.clear()
    check_devices.clear()

main()
    

Credits

Amir Pournasserian

Amir Pournasserian

10 projects • 14 followers
Data scientist, machine learning specialist, IoT nerd. CEO of Momentaj and Founder of uBeac, IoT thinktanks.

Comments