public CW2kClass() { string strCmd = ""; string DeviceName = "device-992-xyz"; string strOutput = ""; Regex re = null; Match match = null; string DeviceID = ""; ConMain = new TelnetSSHLogin(); ConMain.Timeout = 120; bool bResult = ConnectSSH("AppUser", "Pwd***", "192.168.192.52"); if (bResult) { strCmd = "/opt/CSCOpx/bin/dcrcli -u admin"; strCmd += " cmd=lsids dn=" + DeviceName; strOutput = ConMain.cmd(strCmd); if (strOutput.Length > 0) { DeviceID = ""; //Check if Device exists already re = new Regex(@"\nID\s*=\s*([0-9]+)\s+.*", RegexOptions.IgnoreCase); match = re.Match(strOutput); if (match.Success) { DeviceID = match.Groups[1].Value; } if (DeviceID.Length == 0) { Console.WriteLine("CW2K Device dose not exist."); } else { Console.WriteLine("CW2K Device exist with ID: " + DeviceID + "."); } } } }
public ConsoleClass() { ConMain = new TelnetSSHLogin(); //ConMain.PrepareTerminalParameter("Username", "Pwd***", "192.168.192.165", 0, ConnectionMethod.SSH2, "", LogType.Default, ""); ConMain.PrepareTerminalParameter("Username", "Pwd***", "172.25.156.2", 0, ConnectionMethod.Telnet, "", LogType.Binary, ""); if (!ConMain.StartConnection()) { return; } string strOutput = ""; strOutput = ConMain.WaitFor(new string[] { "Username:"******"Login:"******"Password:"******"Press any key to continue" }, false, 0); if ((strOutput == null) || (strOutput.Length == 0)) { return; } if (strOutput.ToLower().Contains("press any key to continue")) { ConMain.print(" "); strOutput = ConMain.WaitFor(new string[] { "username:"******"login:"******"password:"******"username:"******"login:"******"Username"); strOutput = ConMain.WaitForString("Password:"******"Pwd***"); } else if (strOutput.ToLower().Contains("password:"******"Pwd1***"); } else { Console.WriteLine("Error: Found no Loginprompt."); return; } if ((strOutput == null) || (strOutput.Length == 0)) { Console.WriteLine("Error: Found no Prompt after Login."); } Console.WriteLine(ConMain.ShowScreen()); strOutput = ConMain.cmd("terminal length 0"); strOutput = ConMain.cmd("terminal length 1000"); strOutput = ConMain.cmd("terminal width 0"); strOutput = ConMain.cmd("show version"); if (strOutput.Length > 0) { Console.Write(strOutput); } strOutput = ConMain.cmd("show run"); if (strOutput.Length > 0) { Console.Write(strOutput); } ConMain.print("exit"); ConMain.close(); /* * strOutput = ConMain.WaitForString(">"); * Console.WriteLine(ConMain.ShowScreen()); * ConMain.print("exit"); * strOutput = ConMain.WaitForString(":"); * ConMain.print("y"); * strOutput = ConMain.WaitForString(":"); * ConMain.print("n"); * * Console.WriteLine(ConMain.ShowScreen()); */ return; strOutput = ConMain.cmd("ls -alh /"); if (strOutput.Length > 0) { Console.Write(strOutput); } strOutput = ConMain.cmd("ls -a /"); if (strOutput.Length > 0) { Console.Write(strOutput); } strOutput = ConMain.cmd("ls -alh /"); if (strOutput.Length > 0) { Console.Write(strOutput); } ConMain.print("exit"); }