def main(ifname): iw = IW() ip = IPRoute() ifindex = ip.link_lookup(ifname=ifname)[0] ip.close() # CMD_GET_SCAN doesn't require root privileges. # Can use 'nmcli device wifi' or 'nmcli d w' to trigger a scan which will # fill the scan results cache for ~30 seconds. # See also 'iw dev $yourdev scan dump' msg = nl80211_scan.NL80211_GetScan(ifindex) # msg['cmd'] = NL80211_NAMES['NL80211_CMD_GET_SCAN'] # msg['attrs'] = [['NL80211_ATTR_IFINDEX', ifindex]] scan_dump = iw.nlm_request(msg, msg_type=iw.prid, msg_flags=NLM_F_REQUEST | NLM_F_DUMP) for network in scan_dump: for attr in network['attrs']: if attr[0] == 'NL80211_ATTR_BSS': # handy debugging; see everything we captured for bss_attr in attr[1]['attrs']: logger.debug("bss attr=%r", bss_attr) bss = dict(attr[1]['attrs']) print_bss(bss) iw.close()
def run(ifname): iw = IW() ip = IPRoute() ifindex = ip.link_lookup(ifname=ifname)[0] ip.close() # CMD_GET_SCAN doesn't require root privileges. # Can use 'nmcli device wifi' or 'nmcli d w' to trigger a scan which will # fill the scan results cache for ~30 seconds. # See also 'iw dev $yourdev scan dump' msg = nl80211_scan.NL80211_GetScan(ifindex) scan_dump = iw.nlm_request(msg, msg_type=iw.prid, msg_flags=NLM_F_REQUEST | NLM_F_DUMP) jsonator = to_json(scan_dump) return json.dumps({n["bssid"]: n for n in jsonator})
def main(ifname): iw = IW() ip = IPRoute() ifindex = ip.link_lookup(ifname=ifname)[0] ip.close() msg = NL80211_GetScan(ifindex) # msg['cmd'] = NL80211_NAMES['NL80211_CMD_GET_SCAN'] # msg['attrs'] = [['NL80211_ATTR_IFINDEX', ifindex]] scan_dump = iw.nlm_request(msg, msg_type=iw.prid, msg_flags=NLM_F_REQUEST | NLM_F_DUMP) print("SSID BSSID CHAN RATE S:N INT CAPS") for network in scan_dump: for attr in network['attrs']: if attr[0] == 'NL80211_ATTR_BSS': bss = dict(attr[1]['attrs']) print_bss(bss)
iw = IW() ip = IPRoute() ifindex = ip.link_lookup(ifname=ifname)[0] ip.close() # CMD_GET_SCAN doesn't require root privileges. # Can use 'nmcli device wifi' or 'nmcli d w' to trigger a scan which will fill # the scan results cache for ~30 seconds. # See also 'iw dev $yourdev scan dump' msg = nl80211cmd() msg['cmd'] = NL80211_NAMES['NL80211_CMD_GET_SCAN'] msg['attrs'] = [['NL80211_ATTR_IFINDEX', ifindex]] scan_dump = iw.nlm_request(msg, msg_type=iw.prid, msg_flags=NLM_F_REQUEST | NLM_F_DUMP) for network in scan_dump: for attr in network['attrs']: if attr[0] == 'NL80211_ATTR_BSS': # handy debugging; see everything we captured for bss_attr in attr[1]['attrs']: logger.debug("bss attr=%r", bss_attr) bss = dict(attr[1]['attrs']) # NOTE: the contents of beacon and probe response frames may or # may not contain all these fields. Very likely there could be a # keyerror in the following code. Needs a bit more bulletproofing. # print like 'iw dev $dev scan dump"