How to get MAC address of connected Access point?

自闭症网瘾萝莉.ら 提交于 2019-12-24 19:19:42

问题


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 How to sniff only connected AP beacon frame or How to filter connected AP beacon frame using scapy or any alternate idea.

*I am doing it in python 2.7


回答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.all import *

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

sniff(prn=ap_mac)

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

from scapy.all import *

def sniff_ap(pkt):
    if pkt.haslayer(Dot11):
        if pkt.add3 == 'xx.xx.xx.xx.xx.xx':  ## AP MAC
            print(pkt.summary())
        else: pass
    else: pass

sniff(prn=sniff_ap)

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




回答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


来源:https://stackoverflow.com/questions/42918505/how-to-get-mac-address-of-connected-access-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!