Skip to content

Instantly share code, notes, and snippets.

@caspar
Last active November 13, 2023 17:57
Show Gist options
  • Save caspar/4c95f69bc76e1017e6fe299af365b974 to your computer and use it in GitHub Desktop.
Save caspar/4c95f69bc76e1017e6fe299af365b974 to your computer and use it in GitHub Desktop.
Cisco Anyconnect VPN CLI Script (for NYU/other networks)
#!/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