Skip to content

Instantly share code, notes, and snippets.

@mrchoke
Created September 23, 2021 04:59
Show Gist options
  • Save mrchoke/46fe3e2879c6baa08faf4ddc6e62e349 to your computer and use it in GitHub Desktop.
Save mrchoke/46fe3e2879c6baa08faf4ddc6e62e349 to your computer and use it in GitHub Desktop.
openconnect on macOS

การใช้ openconnect แทนการใช้ AnyConnect บน macOS

Install

brew install openconnect

Password

echo "yourpassword" > ~/.vpn_password
chmod 600 ~/.vpn_password

Integrate with shell

Append script below to ~/.bashrc or ~/.zshrc

cat vpnrc.sh >> ~/.zshrc

or

cat vpnrc.sh >> ~/.bashrc

for first time use

source ~/.zshrc

or

source ~/.bashrc

Usage

Up

vpn-up

Down

vpn-down
function vpn-up() {
local VPN_HOST=YOUR_VPN_SERVER_DOMAIN #with out http:// or https://
local VPN_USER=YOUR_USER_NAME
# local GROUP=1 #uncomment if has authgroup
if [ ! -f ~/.vpn_password ]; then
echo "Error: missing ~/.vpn_password"
return
fi
echo "Starting the vpn ..."
echo $(cat ~/.vpn_password) | sudo openconnect \
--background \
--protocol=anyconnect \
# --authgroup=$GROUP \
--passwd-on-stdin \
--user=$VPN_USER $VPN_HOST
}
function vpn-down() {
sudo kill -2 `pgrep openconnect`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment