·
2 分钟阅读时长
·
660
字
·
-阅读
-评论
title: “一键连接Cisco AnyConnect Secure Mobility Client” tags:
- 网络工具 slug: e7f5bd4a date: 2019-10-06 22:57:53 summary: “本文介绍如何一键连接Cisco AnyConnect Secure Mobility Client,包括繁琐的启动步骤、如何自动化等实现细节,以提高连接Cisco AnyConnect Secure Mobility Client的效率。”
For reasons we all know, I couldn’t access the external internet recently, so I used the company VPN — but connecting was time‑consuming with many steps. I looked for a better way.
公司的一封邮件给了很大的帮助,测试成功,这里我也总结一番。
The tedious manual flow
- 启动Cisco AnyConnect Secure Mobility Client
- 输入账户密码
- 选择手机短信验证码校验
- 手机查收短信验证码
- 客户端输入验证码
- 点击确定
How to automate it
安装oath-toolkit
$ brew install oath-toolkitWrite a shell script
比如叫vpn.sh
#!/bin/bash killall 'Cisco AnyConnect Secure Mobility Client' 2>/dev/ null /opt/cisco/anyconnect/bin/vpn disconnect >/dev/null code=`oathtool --totp -b **secret_key**` /opt/cisco/anyconnect/bin/vpn -s connect $1.company.vpn.com << EOF | sed 's/Password: .*/Password: ********/g' **username** **password** **second_authentication_method_index** $code EOF open -g '/Applications/Cisco/Cisco AnyConnect Secure Mobility Client.app'
3. Fill in variables
- `secret_key`: your VPN TOTP secret. For Okta Verify: change password → Extra Verification → Okta Verify Mobile App → Setup → Next → Problems scanning barcode → copy the Secret Key.
- `username`: VPN username
- `password`: VPN password
- `second_authentication_method_index`: the index for the selected second‑factor method; if using the secret key TOTP, provide its index.
到此,最麻烦的手机校验码通过这个secret key搞到了
4. Make the script executable
```bash
chmod +x vpn.sh
```
5. Run the script
```bash
./vpn.sh bj
```
这里为什么会有个bj变量,是因为我司的VPN有多个节点服务,如上脚本对应的是`$1.company.vpn.com`中的变量,假如不需要,去掉这个变量即可。
脚本会自动启动cisco客户端并且连接OK。这样每次就可以不用执行繁琐的步骤了,至少节约2分钟*N次。另外启动时,会杀掉客户端的其它进程,客户端运行中,我们重新执行这个脚本,也不会有问题。
## Nice to have
Automation helps, but opening Terminal each time isn’t elegant. Create an Alfred workflow so typing “vpn” runs the script automatically.
## Final Thoughts
Repetitive steps are manual labor. Use tools to eliminate toil.

