File: yubikey-inventory

package info (click to toggle)
python-yubico 1.3.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 460 kB
  • sloc: python: 2,367; ansic: 128; xml: 20; makefile: 7
file content (37 lines) | stat: -rwxr-xr-x 834 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
"""
Example of how to access more than one connected YubiKey.
"""

import sys
import yubico

def get_all_yubikeys(debug):
    """
    Look for YubiKey with ever increasing `skip' value until an error is returned.

    Return all instances of class YubiKey we got before failing.
    """
    res = []
    try:
        skip = 0
        while skip < 255:
            YK = yubico.find_yubikey(debug = debug, skip = skip)
            res.append(YK)
            skip += 1
    except yubico.yubikey.YubiKeyError:
        pass
    return res

debug = False
if len(sys.argv) > 1:
    debug = (sys.argv[1] == '-v')
keys = get_all_yubikeys(debug)

if not keys:
    print("No YubiKey found.")
else:
    n = 1
    for this in keys:
        print("YubiKey #%02i : %s %s" % (n, this.description, this.status()))
        n += 1