-
-
Save caspar/4c95f69bc76e1017e6fe299af365b974 to your computer and use it in GitHub Desktop.
Cisco Anyconnect VPN CLI Script (for NYU/other networks)
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
#!/bin/bash | |
# FILEPATH: /usr/local/bin/vpn | |
# This script is used to connect/disconnect to a VPN using the Cisco AnyConnect client over the command line. | |
# Usage: | |
# vpn (connect|disconnect) | |
# make file executable | |
chmod +x /usr/local/bin/vpn | |
# Define variables | |
USERNAME="netID/uni" | |
PASSWORD="password" | |
MFA="push" | |
VPN="vpn.nyu.edu" | |
# If no arguments are passed, check if the VPN is connected | |
if [ $# -eq 0 ]; then | |
/opt/cisco/anyconnect/bin/vpn state | grep -q Disconnected | |
if [ $? -eq 0 ]; then | |
echo "VPN is disconnected. Run \$vpn connect" | |
exit 0 | |
else | |
echo "VPN is connected. Run \$vpn disconnect" | |
exit 0 | |
fi | |
fi | |
# If the first argument is connect, connect to the VPN | |
if [ $1 == "connect" ]; then | |
echo "Connecting to VPN" | |
printf "\n\n$PASSWORD\n$MFA\ny" | /opt/cisco/anyconnect/bin/vpn -s connect $VPN | |
exit 0 | |
fi | |
# If the first argument is disconnect, disconnect from the VPN | |
if [ $1 == "disconnect" ]; then | |
echo "Disconnecting from VPN" | |
/opt/cisco/anyconnect/bin/vpn disconnect | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment