我正在尝试通过 Mac 上的命令行登录到我的 VPN (Cisco IPSec)
scutil --nc start "myVPN (Cisco IPSec)" --password "mypassword"
Run Code Online (Sandbox Code Playgroud)

运行该脚本时,我只是在不填写密码的情况下获得通常的弹出窗口,(尽管用户名是自动填充的(就像单击 vpn 登录时一样)。是否可以使用这种方法填写密码,或者是其他任何方式通过命令行连接到VPN?
我编写了一个 shell 脚本,从钥匙串中获取密码,然后将其粘贴到弹出窗口中。您必须使用密码制作一个钥匙串项目才能使其发挥作用。
# VPN.sh
# change these variables for your setup
keychainItem=accountWithPassword # this name has to match "Account" for the entry you make in keychain
VPNName="VPN (Cisco IPSec)" # match the name of the VPN service to run
get_pw () {
security 2>&1 >/dev/null find-generic-password -ga $keychainItem \
|ruby -e 'print $1 if STDIN.gets =~ /^password: "(.*)"$/'
}
echo "fetching VPN credentials from keychain account \"$keychainItem\""
echo "Using VPN service: $VPNName"
scutil --nc start "$VPNName"
sleep 2.7
osascript -e "tell application \"System Events\" to keystroke \"$(get_pw)\""
osascript -e "tell application \"System Events\" to keystroke return"
sleep 2
exit
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4211 次 |
| 最近记录: |