コード例 #1
0
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()
コード例 #2
0
 def getifaces():
     global ifaces, desc
     iw = IW()
     for q in iw.get_interfaces_dump():
         phyname = 'phy%i' % int(q.get_attr('NL80211_ATTR_WIPHY'))
         ifname = q.get_attr('NL80211_ATTR_IFNAME')
         mac = q.get_attr('NL80211_ATTR_MAC')
         desc.append(
             '%s\t%s\t%s\t%s' %
             (q.get_attr('NL80211_ATTR_IFINDEX'), phyname, ifname, mac))
         i = {
             'NL80211_ATTR_WIPHY': int(q.get_attr('NL80211_ATTR_WIPHY')),
             'NL80211_ATTR_IFINDEX': q.get_attr('NL80211_ATTR_IFINDEX'),
             'NL80211_ATTR_IFNAME': ifname,
             'NL80211_ATTR_MAC': mac
         }
         ifaces[ifname] = i
         ifaces[phyname] = i
         ifaces[mac] = i
         iw.close()
コード例 #3
0
            # 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"
            print("BSS {}".format(bss['NL80211_BSS_BSSID']))
            print("\tTSF: {0[VALUE]} ({0[TIME]})".format(
                bss['NL80211_BSS_TSF']))
            print("\tfreq: {}".format(bss['NL80211_BSS_FREQUENCY']))
            print("\tcapability: {}".format(
                bss['NL80211_BSS_CAPABILITY']['CAPABILITIES']))
            print("\tsignal: {0[VALUE]} {0[UNITS]}".format(
                bss['NL80211_BSS_SIGNAL_MBM']['SIGNAL_STRENGTH']))
            print("\tlast seen: {} ms ago".format(
                bss['NL80211_BSS_SEEN_MS_AGO']))

            ies = bss['NL80211_BSS_INFORMATION_ELEMENTS']

            # Be VERY careful with the SSID!  Can contain hostile input.
            print("\tSSID: {}".format(ies['SSID'].decode("utf8")))

            # TODO more IE decodes

iw.close()
コード例 #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
from pyroute2.iwutil import IW

iw = IW()
for q in iw.get_interfaces_dump():
    phyname = 'phy%i' % int(q.get_attr('NL80211_ATTR_WIPHY'))
    print('%i\t%s\t%s\t%s' % (q.get_attr('NL80211_ATTR_IFINDEX'), phyname,
                              q.get_attr('NL80211_ATTR_IFNAME'),
                              q.get_attr('NL80211_ATTR_MAC')))
iw.close()