Created
July 28, 2021 10:48
-
-
Save vBlackOut/d08e8321a604908e4c5aeedaba82835b to your computer and use it in GitHub Desktop.
OTP_OPENVPN_AUTOGENERATE.py
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
import pyotp | |
import time | |
from getpass import getpass | |
import os, sys | |
try: | |
if sys.argv[1] == "-h": | |
print("otp generated command :\n -r renew password LDAP") | |
exit() | |
if sys.argv[1] == "-r": | |
passwordLDAP = getpass("Password LDAP: ") | |
except IndexError: | |
f = open("password.txt", "r") | |
user = f.readline() | |
passwordLDAP = f.readline()[:-6] | |
old_otp = "" | |
while True: | |
uri = pyotp.totp.TOTP('KEY_OTP') | |
otp = uri.now() | |
if old_otp != otp: | |
print("generated password for otp is {}".format(otp), end='\r') | |
old_otp = otp | |
password = "{}{}".format(passwordLDAP, otp) | |
f = open("password.txt", "w") | |
f.write("USERNAME_OPENVPN\n") | |
f.write(password) | |
f.close() | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment