Skip to content Skip to sidebar Skip to footer

How To Get Mac Address Of Connected Access Point?

I am using Scapy to sniff access point(AP) beacon packets and also getting all AP beacon packets and it's MAC address nearby AP but I need exact MAC address of connected AP then Ho

Solution 1:

Assuming the beacon frame is called pkt. pkt.addr1 is the destination MAC, pkt.addr2 is the source MAC and pkt.addr3 is the MAC address of the AP. You could write something like:

from scapy.allimport *

defap_mac(pkt):
    if pkt.haslayer(Dot11)
        if pkt.type == 0and pkt.subtype == 8:
            print('SSID: '+%s+'  MAC:'+%s)(pk.info,pkt.addr3)
        else: passelse: pass

sniff(prn=ap_mac)

to print out all the AP MACs from beacon frames. Then you could use something like:

from scapy.allimport *

defsniff_ap(pkt):
    if pkt.haslayer(Dot11):
        if pkt.add3 == 'xx.xx.xx.xx.xx.xx':  ## AP MACprint(pkt.summary())
        else: passelse: pass

sniff(prn=sniff_ap)

Here is a good link re: beacon frames. https://www.4armed.com/blog/forging-wifi-beacon-frames-using-scapy/

Solution 2:

I choose alternate method i.e using command in python program

Code snippet

def Check_connected_ap():
    cmd =["nmcli -f BSSID,ACTIVE dev wifi list | awk '$2 ~ /yes/ {print $1}'"]
    address = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
    (out, err) = address.communicate()
    print out

Post a Comment for "How To Get Mac Address Of Connected Access Point?"