如何通过脚本断开 forticlient VPN 连接?

如何通过脚本断开 forticlient VPN 连接?

我需要在 Linux 上编写一个 bash 脚本,连接到 VPN,处理一些任务,然后断开连接。

为了连接到 VPN,我使用 forticlient ssl vpn(类似于 fortinet,但用于 VPN)。例如:

./forticlientsslvpn_cli --server 172.17.97.85:10443 --vpnuser forti

有人知道之后如何断开与脚本的连接吗?

答案1

对于你的情况,只需记录forticlientsslvpn_cli进程并向其发送 SIGHUP、SIGQUIT 或 SIGTERM。首选信号是正常断开连接的信号。一个有点肮脏的解决方案(尽管可能对你来说已经足够好了)是只使用killall -s SIG... forticlientsslvpn_cli

Fortigate 设备还支持 Cisco 风格的 IPsec 连接,并且有多个适用于 Linux 的软件客户端,因此替换 SSL VPN 客户端可能是另一种方法。

答案2

在此页面上,有人围绕客户端创建了一个预期脚本来处理断开连接 http://euer.krebsco.de/scripting-the-fortigate-vpn-client.html

#!/usr/bin/expect -f
# cd into the 64 bit folder of the client
# usage: efort.exp

spawn ./forticlientsslvpn_cli --server <VPNIP>:<VPNPORT> --vpnuser <VPNUSER> 2>&1
log_user 0
send_user "Logging in\n"
expect "Password for VPN:"
send "<VPNPASSWORD>\n"

# i needed ths for 'certificate error'
expect "Would you like to connect to this server"
send "Y\n"
send_user "Beginning to connect\n"
expect "STATUS::Tunnel running"
send_user "Tunnel running!\n"

# this is how long the next expect waits for pattern match, in seconds
set timeout 90001
expect "STATUS::Tunnel closed"
send_user "Tunnel closed!\n"
send_user "Dying\n"
close
exit

最后,企业循环脚本,我们就完成了!

#!/bin/sh
cd "$(dirname "$(readlink -f "$0")")"
while sleep 1;do
    expect efort.exp
    echo "Restarting forticlient !"
done

相关内容