Created
October 4, 2024 05:12
-
-
Save iiie/b0d4d17e869386f154ca486429942e61 to your computer and use it in GitHub Desktop.
Secrets should be useful; might as well be colorful too. Reads screenshots of your totp setup QR code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# apt install zbar-tools | |
# pip install pyzbar | |
# pip install pillow | |
# pip install pyotp | |
import os, sys | |
#from urllib.parse import urlparse, parse_qs | |
from datetime import datetime | |
from time import mktime | |
from PIL import Image | |
import pyotp | |
from pyzbar.pyzbar import decode | |
class color: | |
PURPLE = '\033[95m' | |
CYAN = '\033[96m' | |
DARKCYAN = '\033[36m' | |
BLUE = '\033[94m' | |
GREEN = '\033[92m' | |
YELLOW = '\033[93m' | |
RED = '\033[91m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' | |
END = '\033[0m' | |
for f in sys.argv[1:]: | |
for decodeQR in decode(Image.open(os.path.expanduser(f))): | |
uri = decodeQR.data.decode('ascii') | |
#secret = parse_qs(urlparse(uri).query)['secret'][0] | |
#print(pyotp.TOTP(secret).now()) | |
otp = pyotp.parse_uri(uri) | |
#print(otp.provisioning_uri()) | |
print('{otp.issuer} {otp.name}: {color.BOLD}{color.GREEN}{code}{color.END} (exp: {expires})'.format( | |
code=otp.now(), otp=otp, color=color, | |
expires=otp.interval - int(mktime(datetime.today().timetuple()) % otp.interval) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment