Last active
December 19, 2021 23:08
-
-
Save p120ph37/10999441 to your computer and use it in GitHub Desktop.
Expect script to connect to an AnyConnect VPN server on OSX using only oathtool and openconnect (not the Cisco AnyConnect client)
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/expect -f | |
set timeout 30 | |
log_user 0 | |
puts stderr "Generating OTP" | |
spawn oathtool --totp YOUR_SECRET_KEY_HERE | |
expect -re \\d+ | |
set otp $expect_out(0,string) | |
puts stderr "Connecting to VPN server $server" | |
spawn env SPLIT_DNS=YOUR_SPLIT_DNS_DOMAINS_HERE openconnect --script ./vpnc-script https://YOUR_SERVER_HERE --cafile=cacert.pem | |
expect "GROUP:" | |
send "YOUR_GROUP_HERE\n" | |
expect "Username:" | |
send "YOUR_USERNAME_HERE\n" | |
expect "Password:" | |
send "YOUR_PASSWORD_HERE\n" | |
expect "Password:" | |
send "$otp\n" | |
interact |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks! this script was super handy!