使用 Powershell 和 SSH-Session 启动 openconnect VPN
Use Powershell and SSH-Sessions to launch openconnect VPN
我需要从 Windows 上的 powershell 脚本在 linux 路由器上启动 openconnect VPN。
我在 linux 路由器上有一个工作脚本:
echo PASSWORD | sudo openconnect -b --no-dtls --interface=sslvpn host.isp.com --authgroup=SharedVPN --user=username --passwd-on-stdin
当我 运行 本地路由器上的脚本时,vpn 完美启动。
这是我在 windows 机器上的 powershell 脚本:
Import-Module SSH-Sessions
New-SshSession -ComputerName "10.1.43.11" -Username "ubuntu" -KeyFile "C:\keys.pem"
Invoke-SshCommand -ComputerName "10.1.43.11" -Command '/usr/local/sbin/InitializeVPN'
Remove-SshSession -computername "10.1.43.11"
当我 运行 powershell 脚本时,它确实启动了 VPN,但冻结在那里,等待 VPN 结束。我可以终止路由器上的进程,然后 powershell 脚本完成。我需要在后台连接 运行 的 VPN。所以我像这样修改了路由器上的脚本:
echo PASSWORD | sudo openconnect -b --no-dtls --interface=sslvpn host.isp.com --authgroup=SharedVPN --user=username --passwd-on-stdin &
现在,当我 运行 powershell 脚本时,它似乎确实将其发送到后台,但 VPN 无法正常运行,我只能在屏幕上获得部分输出:
Key file specified. Will override password. Trying to read key file...
Successfully connected to 10.1.43.11
10.1.43.11: POST https://host.isp.com/
Connected to ip_addr:443
SSL negotiation with host.isp.com
Connected to HTTPS on host.isp.com
XML POST enabled
POST https://host.isp.com/
Connected to ip_addr:443
SSL negotiation with host.isp.com
Connected to HTTPS on host.isp.com
XML POST enabled
10.1.43.11 should now be disconnected and disposed.
当我直接在路由器上运行它的时候,最后还有"XML POST enabled":
Please enter your username and password.
POST https://host.isp.com/
Got CONNECT response: HTTP/1.1 200 OK
CSTP connected. DPD 30, Keepalive 20
Connected as 10.251.0.29, using SSL
Continuing in background; pid 11049
Connect Banner:
| Access to this system is restricted to authorized users. Unauthorized use is strictly prohibited. Information on this system may be intercepted, recorded, read, copied, and disclosed by and to authorized personnel for official purposes, including criminal investigations. Access or use of this system whether authorized or unauthorized, constitutes your awareness and consent to these terms. DISCONNECT IMMEDIATELY if you do not agree to the conditions stated in this warning.
|
如何让 VPN 在后台启动?
我正在使用 ubuntu 16.04、openconnect 7.08、powershell 5.1、windows 服务器 2016,
从 http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library#Downloads
下载 SSH 会话
好吧,我使用 plink 让它工作了:
C:\bin\plink.exe -i C:\key.ppk ubuntu@10.1.43.11 "nohup /usr/local/sbin/InitializeVPN >/home/ubuntu/VPN.out 2>/home/ubuntu/VPN.err </dev/null &"
stdin、stdout 和 stderr 必须重定向并使用 nohup。
我在这里找到它:Getting ssh to execute a command in the background on target machine
不知道我现在是否会花时间让它与 PowerShell 和 SSH-Sessions 一起工作。也许如果我将来需要更复杂的东西。
我需要从 Windows 上的 powershell 脚本在 linux 路由器上启动 openconnect VPN。
我在 linux 路由器上有一个工作脚本:
echo PASSWORD | sudo openconnect -b --no-dtls --interface=sslvpn host.isp.com --authgroup=SharedVPN --user=username --passwd-on-stdin
当我 运行 本地路由器上的脚本时,vpn 完美启动。 这是我在 windows 机器上的 powershell 脚本:
Import-Module SSH-Sessions
New-SshSession -ComputerName "10.1.43.11" -Username "ubuntu" -KeyFile "C:\keys.pem"
Invoke-SshCommand -ComputerName "10.1.43.11" -Command '/usr/local/sbin/InitializeVPN'
Remove-SshSession -computername "10.1.43.11"
当我 运行 powershell 脚本时,它确实启动了 VPN,但冻结在那里,等待 VPN 结束。我可以终止路由器上的进程,然后 powershell 脚本完成。我需要在后台连接 运行 的 VPN。所以我像这样修改了路由器上的脚本:
echo PASSWORD | sudo openconnect -b --no-dtls --interface=sslvpn host.isp.com --authgroup=SharedVPN --user=username --passwd-on-stdin &
现在,当我 运行 powershell 脚本时,它似乎确实将其发送到后台,但 VPN 无法正常运行,我只能在屏幕上获得部分输出:
Key file specified. Will override password. Trying to read key file...
Successfully connected to 10.1.43.11
10.1.43.11: POST https://host.isp.com/
Connected to ip_addr:443
SSL negotiation with host.isp.com
Connected to HTTPS on host.isp.com
XML POST enabled
POST https://host.isp.com/
Connected to ip_addr:443
SSL negotiation with host.isp.com
Connected to HTTPS on host.isp.com
XML POST enabled
10.1.43.11 should now be disconnected and disposed.
当我直接在路由器上运行它的时候,最后还有"XML POST enabled":
Please enter your username and password.
POST https://host.isp.com/
Got CONNECT response: HTTP/1.1 200 OK
CSTP connected. DPD 30, Keepalive 20
Connected as 10.251.0.29, using SSL
Continuing in background; pid 11049
Connect Banner:
| Access to this system is restricted to authorized users. Unauthorized use is strictly prohibited. Information on this system may be intercepted, recorded, read, copied, and disclosed by and to authorized personnel for official purposes, including criminal investigations. Access or use of this system whether authorized or unauthorized, constitutes your awareness and consent to these terms. DISCONNECT IMMEDIATELY if you do not agree to the conditions stated in this warning.
|
如何让 VPN 在后台启动?
我正在使用 ubuntu 16.04、openconnect 7.08、powershell 5.1、windows 服务器 2016, 从 http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library#Downloads
下载 SSH 会话好吧,我使用 plink 让它工作了:
C:\bin\plink.exe -i C:\key.ppk ubuntu@10.1.43.11 "nohup /usr/local/sbin/InitializeVPN >/home/ubuntu/VPN.out 2>/home/ubuntu/VPN.err </dev/null &"
stdin、stdout 和 stderr 必须重定向并使用 nohup。
我在这里找到它:Getting ssh to execute a command in the background on target machine
不知道我现在是否会花时间让它与 PowerShell 和 SSH-Sessions 一起工作。也许如果我将来需要更复杂的东西。