Skip to content

Instantly share code, notes, and snippets.

@TryTryAgain
Created January 20, 2023 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TryTryAgain/79590be9796f7f2b28818ea1f5381814 to your computer and use it in GitHub Desktop.
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.
#!/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
@TryTryAgain
Copy link
Author

TryTryAgain commented Jan 20, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment