Nic*_*ola 7 authentication vpn client cisco
我需要自动化 Cisco VPN 客户端版本 5.0.07.0440 的登录过程。我尝试过使用这样的命令行,但有问题:
vpnclient.exe connect MyVPNConnection user username pwd password
Run Code Online (Sandbox Code Playgroud)
这将启动连接,但随后会显示“用户身份验证”对话框,询问用户名、密码和域。用户名和密码已填写,不需要域。
要继续,我必须按“确定”按钮。
有没有办法不显示对话框并自动登录VPN?
跑步vpnclient.exe /?:
vpnclient.exe connect MyVPNConnection -s < file.txt
文件.txt
username
password
Run Code Online (Sandbox Code Playgroud)
小智 2
首先,我们需要使用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! ...");
Run Code Online (Sandbox Code Playgroud)
(这可能包含您的特定情况不需要的额外内容。)
| 归档时间: |
|
| 查看次数: |
18942 次 |
| 最近记录: |