Created
January 20, 2023 17:44
-
-
Save TryTryAgain/79590be9796f7f2b28818ea1f5381814 to your computer and use it in GitHub Desktop.
A simple "get OTP" python script utilizing pyotp: Supply an MFA seed and get the current and following/next OTP token readout, useful for getting a quick MFA OTP token provided a seed.
This file contains hidden or 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 python | |
import pyotp | |
import argparse | |
# Variables grabbed from CLI arguments | |
parser = argparse.ArgumentParser( | |
description='Supply MFA seed and get current and next OTP readout') | |
parser.add_argument( | |
'-s', '--seed', | |
required=True | |
) | |
args = parser.parse_args() | |
sanitized_seed = args.seed.replace(' ', '') | |
printed = False | |
totps = pyotp.TOTP(sanitized_seed) | |
totp = totps.now() | |
while True: | |
if not printed: | |
print(totp) | |
if totp != totps.now(): | |
print(totps.now()) | |
break | |
else: | |
printed = True | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You must first
pip install pyotp
Also, if you want it globally available and accessible like in the examples below, you could
cp ./gotp.py /usr/local/bin/gotp
or similar...Examples:
┌👤 michael.lawler @ 🖥️ demo in 🗂🗂️ ~
└❯ gotp -s P5TZXG73Z3WW6LFYAAGHW4S6SYV46G6X6GYJY4AMOQMDTIDGV542E3RL
142817
865105
┌👤 michael.lawler @ 🖥️ demo in 🗂🗂️ ~
└❯ gotp -s 'jbsw y3dp ehpk 3pxp'
069616
298107