Cisco VPN Client自动登录

时间:2014-02-10 16:08:02

标签: login client vpn cisco

我需要自动化Cisco VPN客户端版本5.0.07.0440的登录过程。 我尝试使用这样的命令行,但有一些错误:

vpnclient.exe connect MyVPNConnection user username pwd password

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

要继续,我必须按OK按钮。

有没有办法不显示对话框并自动登录到vpn?

3 个答案:

答案 0 :(得分: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! ...");

(这可能会有额外的东西,对于你的特定情况不是必需的。)

答案 1 :(得分:0)

运行vpnclient.exe /?

enter image description here 这样就可以运行

vpnclient.exe connect MyVPNConnection -s < file.txt

file.txt

username
password

答案 2 :(得分:0)

以下为我工作的Cisco AnyConnect安全移动客户端: (干杯)

  1. 尝试首次使用vpncli.exe连接到VPN,并记下每个按键,即每个命令,每个输入的(\ n),输入的用户名和密码。
  2. 依次将每个命令复制到.login_info文件中。

.login_info示例:

connect unkbown.data-protect.com
\n  
\n
KC23452
\n

注意: 用普通回车代替\ n,这些是我通过vpncli.exe连接时遵循的确切步骤。用户名和组名是自动保存的,这就是第二行和第三行为\ n(输入)的原因。另外,最后一个\ n是必需的。

  1. 转到C:\ Program Files(x86)\ Cisco \ Cisco AnyConnect Secure Mobility Client
  2. 在此处打开CMD
  3. vpncli.exe -s < .login_info