Esempio n. 1
0
def print_retry(wifi, args=None):
    try:
        range_info = Iwrange(wifi.ifname)
    except IOError, (error_number, error_string):
        if (error_number == errno.EOPNOTSUPP) or \
           (error_number == errno.EINVAL) or \
           (error_number == errno.ENODEV):
            sys.stderr.write("%-8.16s  no retry limit/lifetime information.\n\n" % (
                            wifi.ifname, ))
def print_probable_keys(wifi):
    """ Print the probable keys
    """
    # "Check if the interface could support scanning"
    try:
        iwrange = Iwrange(wifi.ifname)
    except IOError, (error_number, error_string):
        sys.stderr.write("%-8.16s  Interface doesn't support scanning.\n\n" %
                         (wifi.ifname))
Esempio n. 3
0
def print_scanning_results(wifi, args=None):
    """ Print the access points detected nearby.

    """
    # "Check if the interface could support scanning"
    try:
        iwrange = Iwrange(wifi.ifname)
    except IOError, (error_number, error_string):
        sys.stderr.write("%-8.16s  Interface doesn't support scanning.\n\n" %
                         (wifi.ifname))
Esempio n. 4
0
def main():
    iwrange = Iwrange(sys.argv[1])
    if iwrange.errorflag:
        print (iwrange.errorflag, iwrange.error)
        sys.exit(1)

    cs=ChanSniffer(sys.argv[1])
    for freq in sorted(iwrange.frequencies):
        #if freq > 3000000000: continue
        #print str(freq/1000000), chanmap[str(freq/1000000)]
        cs.run(freq="%.3fGHz" % (freq/1000000000.0),timeout=23)
    print cs.display().encode('utf8')
Esempio n. 5
0
def print_aps(wifi, args=None):
    """ Print the access points detected nearby.

        iwlist.c uses the deprecated SIOCGIWAPLIST, but iwlist.py uses
        regular scanning (i.e. Wireless.scan()).

    """
    # "Check if the interface could support scanning"
    try:
        iwrange = Iwrange(wifi.ifname)
    except IOError, (error_number, error_string):
        sys.stderr.write("%-8.16s  Interface doesn't support scanning.\n\n" %
                         (wifi.ifname))
Esempio n. 6
0
def getSensitivity(wifi):
    """ Return formatted string with Sensitivity info. """
    try:
        sensitivity = wifi.wireless_info.getSensitivity()
    except IOError as e:
        if (sys.version_info[0] == 3):
            errno, strerror = e.args
        else:
            errno = e[0]
            strerror = e[1]
        return None
    else:
        if sensitivity.fixed:
            fixed = "="
        else:
            fixed = ":"
        iwrange = Iwrange(wifi.ifname)
        return "Sensitivity%c%d/%d  " % (
            fixed, wifi.getSensitivity(), iwrange.sensitivity)
Esempio n. 7
0
def print_encryption(wifi, args=None):
    """ Print encryption keys on the card.

    """
    try:
        keys = wifi.getKeys()
    except IOError as e:
        if (sys.version_info[0] == 3):
            error_number, error_string = e.args
        else:
            error_number = e[0]
            error_string = e[1]
        if (error_number == errno.EOPNOTSUPP) or \
           (error_number == errno.EINVAL) or \
           (error_number == errno.ENODEV):
            # not a wireless device
            sys.stderr.write("%-8.16s  no encryption keys information.\n\n" %
                             (wifi.ifname, ))
    else:
        range_info = Iwrange(wifi.ifname)
        key_sizes = ""
        for index in range(range_info.num_encoding_sizes - 1):
            key_sizes = key_sizes + \
                        repr(range_info.encoding_size[index] * 8) + \
                        ", "
        key_sizes = key_sizes + \
                    repr(range_info.encoding_size[range_info.num_encoding_sizes - 1] * 8) + \
                    "bits"
        print("%-8.16s  %d key sizes : %s" % \
                (wifi.ifname, range_info.num_encoding_sizes, key_sizes))
        print("          %d keys available :" % (len(keys), ))
        for key in keys:
            print("\t\t[%d]: %s" % (key[0], key[1]))
        print("          Current Transmit Key: [%s]" % \
                (wifi.wireless_info.getKey().flags & pythonwifi.flags.IW_ENCODE_INDEX, ))
        if wifi.wireless_info.getKey(
        ).flags & pythonwifi.flags.IW_ENCODE_RESTRICTED:
            print("          Security mode:restricted")
        if wifi.wireless_info.getKey().flags & pythonwifi.flags.IW_ENCODE_OPEN:
            print("          Security mode:open")
        print("\n")
Esempio n. 8
0
def print_aps(wifi, args=None):
    """ Print the access points detected nearby.

        iwlist.c uses the deprecated SIOCGIWAPLIST, but iwlist.py uses
        regular scanning (i.e. Wireless.scan()).

    """
    # "Check if the interface could support scanning"
    try:
        iwrange = Iwrange(wifi.ifname)
    except IOError as e:
        if (sys.version_info[0] == 3):
            error_number, error_string = e.args
        else:
            error_number = e[0]
            error_string = e[1]
        sys.stderr.write("%-8.16s  Interface doesn't support scanning.\n\n" %
                         (wifi.ifname))
    else:
        # "Check for Active Scan (scan with specific essid)"
        # "Check for last scan result (do not trigger scan)"
        # "Initiate Scanning"
        try:
            results = wifi.scan()
        except IOError as e:
            if (sys.version_info[0] == 3):
                error_number, error_string = e.args
            else:
                error_number = e[0]
                error_string = e[1]
            if error_number != errno.EPERM:
                sys.stderr.write(
                    "%-8.16s  Interface doesn't support scanning : %s\n\n" %
                    (wifi.ifname, error_string))
        else:
            if (len(results) == 0):
                print("%-8.16s  Interface doesn't have " % (wifi.ifname, ) + \
                      "a list of Peers/Access-Points")
            else:
                print("%-8.16s  Peers/Access-Points in range:" %
                      (wifi.ifname, ))
                for ap in results:
                    if (ap.quality.quality):
                        if (ap.quality.updated & \
                                    pythonwifi.flags.IW_QUAL_QUAL_UPDATED):
                            quality_updated = "="
                        else:
                            quality_updated = ":"
                        if (ap.quality.updated & \
                                    pythonwifi.flags.IW_QUAL_LEVEL_UPDATED):
                            signal_updated = "="
                        else:
                            signal_updated = ":"
                        if (ap.quality.updated & \
                                    pythonwifi.flags.IW_QUAL_NOISE_UPDATED):
                            noise_updated = "="
                        else:
                            noise_updated = ":"
                        print("    %s : Quality%c%s/%s  Signal level%c%s/%s  Noise level%c%s/%s" % \
                            (ap.bssid,
                            quality_updated,
                            ap.quality.quality,
                            wifi.getQualityMax().quality,
                            signal_updated,
                            ap.quality.getSignallevel(),
                            "100",
                            noise_updated,
                            ap.quality.getNoiselevel(),
                            "100"))
                    else:
                        print("    %s" % (ap.bssid, ))
                print
Esempio n. 9
0
def print_retry(wifi, args=None):
    try:
        range_info = Iwrange(wifi.ifname)
    except IOError as e:
        if (sys.version_info[0] == 3):
            error_number, error_string = e.args
        else:
            error_number = e[0]
            error_string = e[1]
        if (error_number == errno.EOPNOTSUPP) or \
           (error_number == errno.EINVAL) or \
           (error_number == errno.ENODEV):
            sys.stderr.write(
                "%-8.16s  no retry limit/lifetime information.\n\n" %
                (wifi.ifname, ))
    else:
        ifname = "%-8.16s  " % (wifi.ifname, )
        if (range_info.retry_flags & pythonwifi.flags.IW_RETRY_LIMIT):
            if (range_info.retry_flags & pythonwifi.flags.IW_RETRY_MIN):
                limit = "Auto  limit    ;  min limit:%d" % (
                    range_info.min_retry, )
            else:
                limit = "Fixed limit    ;  min limit:%d" % (
                    range_info.min_retry, )
            print(ifname + limit)
            ifname = None
            print("                            max limit:%d" %
                  (range_info.max_retry, ))
        if (range_info.r_time_flags & pythonwifi.flags.IW_RETRY_LIFETIME):
            if (range_info.r_time_flags & pythonwifi.flags.IW_RETRY_MIN):
                lifetime = "Auto  lifetime ;  min lifetime:%d" % (
                    range_info.min_r_time, )
            else:
                lifetime = "Fixed lifetime ;  min lifetime:%d" % (
                    range_info.min_r_time, )
            if ifname:
                print(ifname + lifetime)
                ifname = None
            else:
                print("          " + lifetime)
            print("                            max lifetime:%d" %
                  (range_info.max_r_time, ))
        iwparam = wifi.wireless_info.getRetry()
        if iwparam.disabled:
            print("          Current mode:off")
        else:
            print("          Current mode:on")
            if (iwparam.flags & pythonwifi.flags.IW_RETRY_TYPE):
                if (iwparam.flags & pythonwifi.flags.IW_RETRY_LIFETIME):
                    mode_type = "lifetime"
                else:
                    mode_type = "limit"
                mode = "                 "
                if (iwparam.flags & pythonwifi.flags.IW_RETRY_MIN):
                    mode = mode + " min %s:%d" % (mode_type, iwparam.value)
                if (iwparam.flags & pythonwifi.flags.IW_RETRY_MAX):
                    mode = mode + " max %s:%d" % (mode_type, iwparam.value)
                if (iwparam.flags & pythonwifi.flags.IW_RETRY_SHORT):
                    mode = mode + " short %s:%d" % (mode_type, iwparam.value)
                if (iwparam.flags & pythonwifi.flags.IW_RETRY_LONG):
                    mode = mode + " long %s:%d" % (mode_type, iwparam.value)
                print(mode)
Esempio n. 10
0
def print_scanning_results(wifi, args=None):
    """ Print the access points detected nearby.

    """
    # "Check if the interface could support scanning"
    try:
        iwrange = Iwrange(wifi.ifname)
    except IOError as e:
        if (sys.version_info[0] == 3):
            error_number, error_string = e.args
        else:
            error_number = e[0]
            error_string = e[1]
        sys.stderr.write("%-8.16s  Interface doesn't support scanning.\n\n" %
                         (wifi.ifname))
    else:
        # "Check for Active Scan (scan with specific essid)"
        # "Check for last scan result (do not trigger scan)"
        # "Initiate Scanning"
        try:
            results = wifi.scan()
        except IOError as e:
            if (sys.version_info[0] == 3):
                error_number, error_string = e.args
            else:
                error_number = e[0]
                error_string = e[1]
            if error_number != errno.EPERM:
                sys.stderr.write(
                    "%-8.16s  Interface doesn't support scanning : %s\n\n" %
                    (wifi.ifname, error_string))
        else:
            if (len(results) == 0):
                print("%-8.16s  No scan results" % (wifi.ifname, ))
            else:
                (num_channels, frequencies) = wifi.getChannelInfo()
                print("%-8.16s  Scan completed :" % (wifi.ifname, ))
                index = 1
                for ap in results.aplist:
                    print("          Cell %02d - Address: %s" %
                          (index, ap.bssid))
                    print("                    ESSID:\"%s\"" % (ap.essid, ))
                    print("                    Mode:%s" % (ap.mode, ))
                    print("                    Frequency:%s (Channel %d)" % \
                        (wifi._formatFrequency(ap.frequency.getFrequency()),
                        frequencies.index(wifi._formatFrequency(
                            ap.frequency.getFrequency())) + 1))
                    if (ap.quality.updated & \
                                pythonwifi.flags.IW_QUAL_QUAL_UPDATED):
                        quality_updated = "="
                    else:
                        quality_updated = ":"
                    if (ap.quality.updated & \
                                pythonwifi.flags.IW_QUAL_LEVEL_UPDATED):
                        signal_updated = "="
                    else:
                        signal_updated = ":"
                    if (ap.quality.updated & \
                                pythonwifi.flags.IW_QUAL_NOISE_UPDATED):
                        noise_updated = "="
                    else:
                        noise_updated = ":"
                    print("                    " + \
                        "Quality%c%s/%s  Signal level%c%s/%s  Noise level%c%s/%s" % \
                        (quality_updated,
                        ap.quality.quality,
                        wifi.getQualityMax().quality,
                        signal_updated,
                        ap.quality.getSignallevel(),
                        "100",
                        noise_updated,
                        ap.quality.getNoiselevel(),
                        "100"))
                    # This code on encryption keys is very fragile
                    key_status = ""
                    if (ap.encode.flags & pythonwifi.flags.IW_ENCODE_DISABLED):
                        key_status = "off"
                    else:
                        if (ap.encode.flags
                                & pythonwifi.flags.IW_ENCODE_NOKEY):
                            if (ap.encode.length <= 0):
                                key_status = "on"
                    print("                    Encryption key:%s" %
                          (key_status, ))
                    if len(ap.rate) > 0:
                        for rate_list in ap.rate:
                            # calc how many full lines of bitrates
                            rate_lines = len(rate_list) // 5
                            # calc how many bitrates on last line
                            rate_remainder = len(rate_list) % 5
                            line = 0
                            # first line should start with a label
                            rate_line = "                    Bit Rates:"
                            while line < rate_lines:
                                # print full lines
                                if line > 0:
                                    # non-first lines should start *very* indented
                                    rate_line = "                              "
                                rate_line = rate_line + "%s; %s; %s; %s; %s" % \
                                    tuple(wifi._formatBitrate(x) for x in
                                        rate_list[line * 5:(line * 5) + 5])
                                line = line + 1
                                print(rate_line)
                            if line > 0:
                                # non-first lines should start *very* indented
                                rate_line = "                              "
                            # print non-full line
                            print(rate_line + "%s; "*(rate_remainder - 1) % \
                                tuple(wifi._formatBitrate(x) for x in
                                    rate_list[line * 5:line * 5 + rate_remainder - 1]) + \
                                "%s" % (wifi._formatBitrate(
                                        rate_list[line * 5 + rate_remainder - 1])))
                    index = index + 1
            print("")
Esempio n. 11
0
def print_encryption(wifi, args=None):
    """ Print encryption keys on the card.

    """
    try:
        keys = wifi.getKeys()
    except IOError, (error_number, error_string):
        if (error_number == errno.EOPNOTSUPP) or \
           (error_number == errno.EINVAL) or \
           (error_number == errno.ENODEV):
            # not a wireless device
            sys.stderr.write("%-8.16s  no encryption keys information.\n\n" %
                             (wifi.ifname, ))
    else:
        range_info = Iwrange(wifi.ifname)
        key_sizes = ""
        for index in range(range_info.num_encoding_sizes - 1):
            key_sizes = key_sizes + \
                        repr(range_info.encoding_size[index] * 8) + \
                        ", "
        key_sizes = key_sizes + \
                    repr(range_info.encoding_size[range_info.num_encoding_sizes - 1] * 8) + \
                    "bits"
        print "%-8.16s  %d key sizes : %s" % \
                (wifi.ifname, range_info.num_encoding_sizes, key_sizes)
        print "          %d keys available :" % (len(keys), )
        for key in keys:
            print "\t\t[%d]: %s" % (key[0], key[1])
        print "          Current Transmit Key: [%s]" % \
                (wifi.wireless_info.getKey().flags & pythonwifi.flags.IW_ENCODE_INDEX, )
Esempio n. 12
0
            fixed = ":"
        return "Tx-Power%c%s   " % (fixed, wifi.getTXPower())


def getSensitivity(wifi):
    """ Return formatted string with Sensitivity info. """
    try:
        sensitivity = wifi.wireless_info.getSensitivity()
    except IOError, (errno, strerror):
        return None
    else:
        if sensitivity.fixed:
            fixed = "="
        else:
            fixed = ":"
        iwrange = Iwrange(wifi.ifname)
        return "Sensitivity%c%d/%d  " % (fixed, wifi.getSensitivity(),
                                         iwrange.sensitivity)


def getRetrylimit(wifi):
    """ Return formatted string with Retry info. """
    try:
        retry = wifi.wireless_info.getRetry()
    except IOError, (errno, strerror):
        return None
    else:
        modifier = ""
        if (retry.flags & IW_RETRY_MIN):
            modifier = " min"
        elif (retry.flags & IW_RETRY_MAX):