Cisco VPN客户端自动登录

问题描述 投票:0回答:2

我需要自动执行Cisco VPN Client 5.0.07.0440版本的登录过程。我已经尝试过使用这样的命令行,但是出了点问题:

vpnclient.exe connect MyVPNConnection user username pwd password

这将启动连接,但随后会显示“用户身份验证”对话框,询问用户名,密码和域。用户名和密码已经填写,不需要域。

要继续,我必须按确定按钮。

是否有一种方法不显示对话框并自动登录到VPN?

login client vpn cisco
2个回答
1
投票

首先,我们需要对vpncli.exe开关使用-s命令行方法。它可以从命令行或脚本运行。如果您正在C#中寻找解决方案:

//file = @"C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe"
var file = vpnInfo.ExecutablePath;
var host = vpnInfo.Host;
var profile = vpnInfo.ProfileName;
var user = vpnInfo.User;
var pass = vpnInfo.Password;
var confirm = "y";

var proc = new Process
{
    StartInfo = new ProcessStartInfo
    {
        FileName = file,
        Arguments = string.Format("-s"),
        UseShellExecute = false,
        RedirectStandardInput = true,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
    }
};

proc.OutputDataReceived += (s, a) => stdOut.AppendLine(a.Data);
proc.ErrorDataReceived += (s, a) => stdOut.AppendLine(a.Data);

//make sure it is not running, otherwise connection will fail
var procFilter = new HashSet<string>() { "vpnui", "vpncli" };
var existingProcs = Process.GetProcesses().Where(p => procFilter.Contains(p.ProcessName));
if (existingProcs.Any())
{
    foreach (var p in existingProcs)
    {
        p.Kill();
    }
}

proc.Start();
proc.BeginOutputReadLine();

//simulate profile file
var simProfile = string.Format("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}"
    , Environment.NewLine
    , string.Format("connect {0}", host)
    , profile
    , user
    , pass
    , confirm
    );

proc.StandardInput.Write(simProfile);
proc.StandardInput.Flush();

//todo: these should be a configurable value
var waitTime = 500; //in ms
var maxWait = 10;

var count = 0;
var output = stdOut.ToString();
while (!output.Contains("state: Connected"))
{
    output = stdOut.ToString();

    if (count > maxWait)
        throw new Exception("Unable to connect to VPN.");

    count++;
    Thread.Sleep(waitTime);
}
stdOut.Append("VPN connection established! ...");

((这可能有多余的东西,对于您的特定情况不是必需的。)


0
投票

运行vpnclient.exe /?

enter image description here这样就可以运行

vpnclient.exe connect MyVPNConnection -s < file.txt

file.txt

username
password
© www.soinside.com 2019 - 2024. All rights reserved.