anyconnect vpn 一键登录保存密码的方法,Mac 、Windows、Android
Mac 下 安装 原版 anconnect ,然后使用如下脚本即可,断线自动重连。
#!/bin/bash
# connect some vpn without password
USERNAME= # your username
PASSWORD= # your password
VPN_URL="your vpn and port"
VPN_BIN="/opt/cisco/anyconnect/bin/vpn"
ANYCONNECT_PATH="/Applications/Cisco/Cisco AnyConnect Secure Mobility Client.app"
get_anyclient_ui_pid() {
local pid=$(ps -ef | grep "$ANYCONNECT_PATH" | grep -v 'grep' | awk '{print $2}')
echo $pid
if [[ -z "$pid" ]]; then
return 1
else
return 0
fi
}
kill_anyconnect_ui() {
$VPN_BIN disconnect
local pid=$(get_anyclient_ui_pid)
# echo "PID: $pid"
if [[ -n "$pid" ]]; then
kill -9 $pid
fi
}
open_client_ui() {
if ! get_anyclient_ui_pid &> /dev/zero; then
open "$ANYCONNECT_PATH"
fi
}
connect() {
# sudo /opt/cisco/anyconnect/bin/vpnagentd
kill_anyconnect_ui
$VPN_BIN -s << EOF
connect $VPN_URL
1
$USERNAME
$PASSWORD
EOF
open_client_ui
}
main() {
if [[ -z "$USERNAME" || -z "$PASSWORD" || -z "$VPN_URL" ]]; then
echo "Error: empty user info"
exit 1
fi
case "$1" in
stop|s )
$VPN_BIN disconnect
;;
* )
connect
esac
}
main "$*"
Windows 下 使用 openconnect-gui 这个软件即可保存密码,界面简洁。
Android 下 OpenConnect 这个app即可,不要使用思科原版 AnyConnect.
文章评论