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

posted @ 2021-06-15 15:08  高宏宇  阅读(3735)  评论(0)    收藏  举报