Search code examples
pythonnetwork-programmingscapyrssi

Retrieving RSSI values from all devices connected to network


I'm building an application that lists the hostnames of devices connected to the network and their corresponding RSSI values. Is there any way I can collect this information for each network device?

I was able to use the WLAN API (I'm on Windows) in Python to get the RSSI values for nearby wireless LAN networks, but I want to get that information for each device connected to the network. I also tried using the scapy module in Python, but I was only able to get the hostnames, not the RSSI values.

I've done a lot of digging and haven't found a definitive answer to this. Just looking for some direction. Is this possible?


Solution

  • Here is an idea based on one approach you seem to have pursued.

    Code will collect the signal strength using one station as a monitoring station.

    To run correctly on a Macbook you need to disconnect the interface from the network before running.

    Here is sample output (x added to obscure mac addresses):

    x4:x9:x2:ed:03:39 -78
    x4:xd:x1:55:e8:de -86
    x0:xa:x6:13:e6:ac -78
    x8:x3:xd:63:b6:85 -87
    x0:x8:xa:04:24:a2 -78
    x0:x1:x6:d2:2a:65 -88
    
    from scapy.all import *
    
    conf.use_pcap=True
    
    maxrssi = {}
    
    def callBack(pkt):
        # print(pkt.show())
        if pkt.haslayer(Dot11):
            key = None
            if not pkt.FCfield.to_DS and pkt.FCfield.from_DS:
                if pkt.addr3 is not None:
                    key = pkt.addr3
            else:
                if pkt.addr2 is not None:
                    key = pkt.addr2
            if key is not None:
                if key in maxrssi.keys():
                    if maxrssi[key] < pkt.dBm_AntSignal:
                        maxrssi[key] = pkt.dBm_AntSignal
                        #print("NEW MAX for ", key, maxrssi[key]);
                else:
                    maxrssi[key] = pkt.dBm_AntSignal
                    #print("NEW MAX for ", key, maxrssi[key]);
    
    sniff(iface='en0', monitor='True', prn=callBack, count=200)
    for sta in maxrssi:
        print(sta, maxrssi[sta])
    

    Suggesting, because another user recently asked how to get RSSI using python