欢迎来到高宏宇-Blog-资深运维工程师|

高宏宇

园龄:5年2个月粉丝:4关注:5

macOS安装使用OpenConnect客户端替代cisco连接公司内网环境

mac_os安装openconnect服务

brew install openconnect

使用OpenConnect客户端拨通VPN,打开终端执行以下命令:

sudo openconnect -u 【VPN用户名】 https://ocvpn.sysu.edu.cn

启停脚本

#!/bin/bash
#vpn启动脚本
##
start(){
if [ $(ps -ef |grep openconnect |grep -v grep|wc -l) -eq 0 ]
then
openconnect kvpn.ksyun.com --protocol=anyconnect --user w_gaohongyu --authgroup=ksyun -b --pid-file=/Users/gaohongyu/scripts/data/openconnect/pid
[ $? -eq 0 ] && echo "openconnect is starting" || echo "openconnect start is error"
else
echo "openconnect is running,please do not start it again"
fi
}
stop(){
if [ $(ps -ef |grep openconnect |grep -v grep|wc -l) -ne 0 ]
then
kill $(cat /Users/gaohongyu/scripts/data/openconnect/pid) && rm -rf /Users/gaohongyu/scripts/data/openconnect/pid
[ $? -eq 0 ] && echo "openconnect is stopped" || echo "openconnect stop is error"
else
echo "openconnect is not running"
fi
}
restart(){
stop
start
}
status(){
if [ $(ps -ef |grep openconnect |grep -v grep|wc -l) -eq 0 ]
then
echo "openconnect is not running"
else
echo "openconnect is running"
fi
}
#
##
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "usage:$0 (start|stop|restart|status)"
exit 1
esac

写到环境变量开启快捷键

cat .zshrc
function vpn-start {
sudo /Users/gaohongyu/ghy/shell/vpn start
}
function vpn-stop {
sudo /Users/gaohongyu/ghy/shell/vpn stop
}
function vpn-restart {
sudo /Users/gaohongyu/ghy/shell/vpn restart
}
function vpn-status {
sudo /Users/gaohongyu/ghy/shell/vpn status
}

启动:vpn-start
停止:vpn-stop
重启:vpn-restart
状态:vpn-status

本文作者:高宏宇

本文链接:https://www.cnblogs.com/gaohongyu/p/14885553.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   高宏宇  阅读(3276)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起