Created
May 5, 2020 19:05
-
-
Save konstantinj/b8f4f550cb4f2e6fd13d3b61863f6421 to your computer and use it in GitHub Desktop.
A python script to automate otp in openvpn sessions
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 | |
import sys | |
# https://github.com/tadeck/onetimepass | |
import onetimepass as otp | |
# https://github.com/pexpect/pexpect | |
import pexpect | |
secret = open('.home-office.secret', 'r').read().strip() | |
code = str(otp.get_totp(secret)).zfill(6) | |
conn = pexpect.spawn('sudo openvpn --config home-office.ovpn --auth-retry interact') | |
conn.logfile = sys.stdout.buffer | |
conn.expect('CHALLENGE') | |
conn.delaybeforesend = 1 | |
conn.sendline(code) | |
conn.expect('Initialization Sequence Completed') | |
print("Escape character is '^]'.\n") | |
sys.stdout.buffer.write(conn.after) | |
sys.stdout.buffer.flush() | |
conn.interact() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment