public CreateShellStream ( string terminalName, uint columns, uint rows, uint width, uint height, int bufferSize ) : |
||
terminalName | string | The |
columns | uint | The terminal width in columns. |
rows | uint | The terminal width in rows. |
width | uint | The terminal height in pixels. |
height | uint | The terminal height in pixels. |
bufferSize | int | Size of the buffer. |
return |
private static void connect(string hostName, string userName, string password) { if (client != null && client.IsConnected) return; var connectionInfo = new KeyboardInteractiveConnectionInfo(hostName, userName); connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e) { foreach (var prompt in e.Prompts) prompt.Response = password; }; client = new SshClient(connectionInfo); client.Connect(); sshStream = client.CreateShellStream("", 80, 40, 80, 40, 1024); shellCommand("python", null); using (var sr = new System.IO.StreamReader("queryJoints.py")) { String line; while ((line = sr.ReadLine()) != null) pythonCommand(line); } }
static void Main(string[] args) { Console.WriteLine("fd"); try { ssh = new SshClient("10.141.3.110", "root", "ismail"); ssh.Connect(); //status = true; //timer_enable(); } //catch (Exception ex) // { // Console.Write(ex.Message); //} catch { } if (true) try { stream = ssh.CreateShellStream("xterm", 80, 50, 1024, 1024, 1024); Thread.Sleep(100); stream.WriteLine("telnet localhost 6571"); Thread.Sleep(100); } catch (Exception) { Console.WriteLine("hata"); } Console.ReadKey(); }
public void Connect(ConnectionSettings settings, int terminalCols, int terminalRows) { Settings = settings; if (dataThread != null) throw new InvalidOperationException("Already connecting to a server."); dataThread = new Thread(() => { #if USE_LIBSSHNET var connection = new LibSshNetConnection(serverAddress, username, (authentications.First() as PasswordAuthentication).Password); stream = connection.GetStream(); #else try { var authentications = new List<AuthenticationMethod>(); if (!string.IsNullOrEmpty(settings.KeyFilePath)) { var privateKeyFile = new PrivateKeyFile(settings.KeyFilePath, settings.KeyFilePassphrase); authentications.Add(new PrivateKeyAuthenticationMethod(settings.Username, privateKeyFile)); } authentications.Add(new PasswordAuthenticationMethod(settings.Username, settings.Password)); ConnectionInfo connectionInfo = new ConnectionInfo(settings.ServerAddress, settings.ServerPort, settings.Username, authentications.ToArray()); Client = new SshClient(connectionInfo); Client.Connect(); Client.KeepAliveInterval = TimeSpan.FromSeconds(20); Stream = Client.CreateShellStream("xterm-256color", (uint) terminalCols, (uint) terminalRows, 0, 0, 1000); if (Connected != null) Connected(this, EventArgs.Empty); } catch (Exception ex) { ConnectionFailedEventArgs args = null; if (ex is Renci.SshNet.Common.SshPassPhraseNullOrEmptyException || ex is InvalidOperationException) args = new ConnectionFailedEventArgs(ConnectionError.PassphraseIncorrect, ex.Message); else if (ex is SocketException) args = new ConnectionFailedEventArgs(ConnectionError.NetError, ex.Message); else if (ex is Renci.SshNet.Common.SshAuthenticationException) args = new ConnectionFailedEventArgs(ConnectionError.AuthenticationError, ex.Message); else throw; if (Failed != null) Failed(this, args); } #endif }); dataThread.Name = "Data Thread"; dataThread.IsBackground = true; dataThread.Start(); }
private void SSHForm_Load(object sender, EventArgs e) { client = new SshClient(server, port, user,pwd); client.Connect(); string reply = string.Empty; shellStream = client.CreateShellStream("dumb", 80, 24, 800, 600, 1024); reply = shellStream.Expect(new Regex(@":.*>#"), new TimeSpan(0, 0, 3)); shellStream.DataReceived += ShellStream_DataReceived; richTextBox1.Text = "server connected\n"; richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.ScrollToCaret(); }
static void Main(string[] args) { Console.WriteLine("fd"); try { ssh = new SshClient("10.141.3.110", "root", "ismail"); ssh.Connect(); //status = true; //timer_enable(); } //catch (Exception ex) // { // Console.Write(ex.Message); //} catch { } if (true) { try { stream = ssh.CreateShellStream("xterm", 80, 50, 1024, 1024, 1024); Thread.Sleep(100); stream.WriteLine("telnet localhost 6571"); Thread.Sleep(100); } catch (Exception) { Console.WriteLine("hata"); } } Console.ReadKey(); }
/// <summary> /// /// </summary> /// <returns></returns> public virtual bool Execute() { var decryptedPassword = EncrytionHelper.Decrypt(SshPassword); var client = new Renci.SshNet.SshClient(SshHost, SshLogin, decryptedPassword); client.Connect(); var termkvp = new Dictionary <TerminalModes, uint>(); termkvp.Add(TerminalModes.ECHO, 53); var shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024, termkvp); if (IsRoot) { SwitchToRoot(decryptedPassword, shellStream); } WriteStream(Command, shellStream); var result = ReadStream(shellStream); _log.Information(result); _log.Success("Command Execute finished!"); client.Disconnect(); return(true); }
public void ExeSSH(Object s) { using (var conninfo = new PasswordConnectionInfo(ip, log, pass)) { // try Renci.SshNet.SshClient client = new Renci.SshNet.SshClient(conninfo); // conninfo.Timeout = TimeSpan.FromSeconds(50); try { client.Connect(); } catch (Exception ex) { } try { Renci.SshNet.ShellStream stream = client.CreateShellStream("ssh", 180, 324, 1800, 3600, 8000); foreach (string command in list) { stream.Write(command + "\n"); System.Threading.Thread.Sleep(5000); string temp_string = stream.Read(); // File.WriteAllText(path, temp_string, Encoding.UTF8); File.WriteAllText("C:/" + ip + ".txt", temp_string, Encoding.UTF8); System.Threading.Thread.Sleep(5000); } client.Disconnect(); } catch (Exception ex) { } } }
public void Connect() { sshClient.Connect(); ss = sshClient.CreateShellStream(Host, 10, 10, 10, 10, 1024); thr = new Thread(thrRead); thr.Start(); }
private static MyAsyncInfo info; // unique class containing information obtained from an asynchronous read // constructor that initializes the client object and creates a connection to the remote terminal public SSH(string IP, string user, string pass) { // initilizes client object containing server information client = new SshClient(IP, user, pass); // connects to the server client.Connect(); // creates a stream to communicate with the remote terminal stream = client.CreateShellStream(@"xterm", 80, 24, 800, 600, 2048); }
public static void flash_px4(string firmware_file) { if (is_solo_alive) { using (SshClient client = new SshClient("10.1.1.10", 22, "root", "TjSDBkAu")) { client.KeepAliveInterval = TimeSpan.FromSeconds(5); client.Connect(); if (!client.IsConnected) throw new Exception("Failed to connect ssh"); var retcode = client.RunCommand("rm -rf /firmware/loaded"); using (ScpClient scpClient = new ScpClient(client.ConnectionInfo)) { scpClient.Connect(); if (!scpClient.IsConnected) throw new Exception("Failed to connect scp"); scpClient.Upload(new FileInfo(firmware_file), "/firmware/" + Path.GetFileName(firmware_file)); } var st = client.CreateShellStream("bash", 80, 24, 800, 600, 1024*8); // wait for bash prompt while (!st.DataAvailable) System.Threading.Thread.Sleep(200); st.WriteLine("loadPixhawk.py; exit;"); st.Flush(); StringBuilder output = new StringBuilder(); while (client.IsConnected) { var line = st.Read(); Console.Write(line); output.Append(line); System.Threading.Thread.Sleep(100); if (output.ToString().Contains("logout")) break; } } } else { throw new Exception("Solo is not responding to pings"); } }
static void _main() { BlackCore.basic.cParams args = bcore.app.args; client = new System.Net.Sockets.TcpClient(); int wavInDevices = WaveIn.DeviceCount; int selWav = 0; for (int wavDevice = 0; wavDevice < wavInDevices; wavDevice++) { WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(wavDevice); Console.WriteLine("Device {0}: {1}, {2} channels", wavDevice, deviceInfo.ProductName, deviceInfo.Channels); } Console.Write("Select device: "); selWav = int.Parse(Console.ReadLine()); Console.WriteLine("Selected device is " + selWav.ToString()); sshClient = new SshClient(args["host"], args["user"], args["pass"]); sshClient.Connect(); if (sshClient.IsConnected) { shell = sshClient.CreateShellStream("xterm", 50, 50, 640, 480, 17640); Console.WriteLine("Open listening socket..."); shell.WriteLine("nc -l " + args["port"] + "|pacat --playback"); System.Threading.Thread.Sleep(2000); Console.WriteLine("Try to connect..."); client.Connect(args["host"], int.Parse(args["port"])); if (!client.Connected) return; upStream = client.GetStream(); //==================== WaveInEvent wavInStream = new WaveInEvent(); wavInStream.DataAvailable += new EventHandler<WaveInEventArgs>(wavInStream_DataAvailable); wavInStream.DeviceNumber = selWav; wavInStream.WaveFormat = new WaveFormat(44100, 16, 2); wavInStream.StartRecording(); Console.WriteLine("Working....."); Console.ReadKey(); sshClient.Disconnect(); client.Close(); wavInStream.StopRecording(); wavInStream.Dispose(); wavInStream = null; } }
internal BasicRemoteOperations(IDeploymentContext context, IHost host) { Context = context; Sftp = new SftpClient(host.Hostname, host.Username, host.Password) { OperationTimeout = TimeSpan.FromMinutes(2), ConnectionInfo = {Timeout = TimeSpan.FromMinutes(2)}, BufferSize = 1024*16 }; Sftp.Connect(); Shell = new SshClient(host.Hostname, host.Username, host.Password); Shell.Connect(); ShellStream = Shell.CreateShellStream( String.Format("{0}@{1}", host.Username, host.Hostname), 0, 0, 0, 0, 1024); }
public PythonConnection(string hostName, string userName, string password) { var connectionInfo = new KeyboardInteractiveConnectionInfo(hostName, userName); connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e) { foreach (var prompt in e.Prompts) prompt.Response = password; }; client = new SshClient(connectionInfo); client.Connect(); sshStream = client.CreateShellStream("", 80, 40, 80, 40, 1024); shellCommand("python", null); }
public MySshStream(string host, string username, string password) { SshClient ssh = new SshClient(GenerateConnectionInfo(host, username, password)); ssh.Connect(); if (!ssh.IsConnected) throw new Exception("Can't connect to host: " + ssh.ConnectionInfo.Host); var x = new Dictionary<Renci.SshNet.Common.TerminalModes, uint>(); //x.Add(Renci.SshNet.Common.TerminalModes.VERASE, 0); stream = ssh.CreateShellStream("dumb", 80, 24, 800, 600, 1024,x); stream.DataReceived += stream_DataReceived; reader = new StreamReader(stream); writer = new StreamWriter(stream); writer.AutoFlush = true; outputWriter = new StreamWriter(memoryStream); shellOutpu = new StreamReader(memoryStream); }
public void ReadBack() { var info = util.GetUsernameAndPassword(); var sclist = new CredentialSet(info.Item1); var passwordInfo = sclist.Load().Where(c => c.Username == info.Item2).FirstOrDefault(); if (passwordInfo == null) { throw new ArgumentException(string.Format("Please create a generic windows credential with '{0}' as the target address, '{1}' as the username, and the password for remote SSH access to that machine.", info.Item1, info.Item2)); } // Create the connection, but do it lazy so we don't do anything if we aren't used. var host = info.Item1; var username = info.Item2; var password = passwordInfo.Password; // Do the work. var con = new SshClient(host, username, password); con.Connect(); var s = con.CreateShellStream("Commands", 240, 200, 132, 80, 1024); var reader = new StreamReader(s); var writer = new StreamWriter(s); writer.AutoFlush = true; // Do the read command writer.WriteLine("read -p \"hi there: \" bogus"); Thread.Sleep(200); writer.Write("Life Is Great\n"); Thread.Sleep(200); writer.WriteLine("set | grep bogus"); Thread.Sleep(200); string l = ""; while ((l = reader.ReadLine()) != null) { Console.WriteLine(l); } Assert.Inconclusive(); }
public bool Connect() { System.Diagnostics.Debug.WriteLineIf(DEBUG, "ssh: connecting ...."); try { ConnectionInfo info = new PasswordConnectionInfo(_host,_port, _user, _pw); _client = new SshClient(info); _client.ErrorOccurred += SSHError; _client.Connect(); _stream = _client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); System.Diagnostics.Debug.WriteLineIf(DEBUG, "ssh: connected"); return true; } catch (System.Exception e) { System.Diagnostics.Debug.WriteLineIf(DEBUG, "ssh: error while connecting:"); System.Diagnostics.Debug.WriteLine(e.Message); System.Diagnostics.Debug.WriteLine(e.InnerException); return false; } }
public void ExSSH(string ip, string log, string pass, List <String> list) { // foreach (string ipadd in ip) // { using (var conninfo = new PasswordConnectionInfo(ip, log, pass)) { Renci.SshNet.SshClient client = new Renci.SshNet.SshClient(conninfo); client.Connect(); Renci.SshNet.ShellStream stream = client.CreateShellStream("ssh", 180, 324, 1800, 3600, 8000); foreach (string command in list) { // var command = "show config modified"; stream.Write(command + "\n"); System.Threading.Thread.Sleep(10000); string temp_string = stream.Read(); // Console.Write(temp_string); File.WriteAllText("C:/" + ip + " thread n- " + System.Threading.Thread.CurrentThread.ManagedThreadId + ".txt", temp_string, Encoding.UTF8); // System.Threading.Thread.Sleep(5000); } client.Disconnect(); // } } }
private void btnUnixDetect_Click(object sender, RoutedEventArgs e) { try { var KeyboardInteractive = new Ssh.KeyboardInteractiveAuthenticationMethod(Host.Username); var Password = new Ssh.PasswordAuthenticationMethod(Host.Username, AES.DecryptString(Host.Password)); var encryptedPassword = Host.Password; KeyboardInteractive.AuthenticationPrompt += delegate(object sender1, Ssh.Common.AuthenticationPromptEventArgs e1) { foreach (var prompt in e1.Prompts) { if (prompt.Request.ToLower().Contains("password")) { prompt.Response = AES.DecryptString(encryptedPassword); } } }; var conn = new Ssh.ConnectionInfo(Host.Value, Host.Username, Password, KeyboardInteractive); using (Ssh.SshClient client = new Ssh.SshClient(conn)) { client.Connect(); var termdic = new Dictionary <Ssh.Common.TerminalModes, uint>(); termdic.Add(Ssh.Common.TerminalModes.ECHO, 0); using (var shell = client.CreateShellStream("gogrid", 80, 24, 800, 600, 1024, termdic)) { using (var output = new StreamReader(shell)) using (var input = new StreamWriter(shell)) { input.AutoFlush = true; while (shell.Length == 0) { Thread.Sleep(500); } //shell.WriteLine("stty raw -echo"); // disable echo while (shell.Length != 0) { shell.Read(); } shell.Write("([ -d ~/oraInventory/ContentsXML/ ] && [ -e ~/oraInventory/ContentsXML/inventory.xml ]) && echo epmi1 || echo epmi0\n"); while (shell.Length == 0) { Thread.Sleep(500); } var resp = shell.ReadLine(); while (shell.Length != 0) { shell.Read(); } if (System.Text.RegularExpressions.Regex.IsMatch(resp, "epmi1$")) { shell.Write("cat ~/oraInventory/ContentsXML/inventory.xml\n"); while (shell.Length == 0) { Thread.Sleep(500); } resp = Read(output, true); XmlDocument doc = new XmlDocument(); doc.LoadXml(resp); var nodes = doc.SelectNodes("INVENTORY/HOME_LIST/HOME"); for (int i = 0; i < nodes.Count; i++) { if (Regex.IsMatch(nodes[i].Attributes["NAME"].Value, @"EpmSystem_\S+")) { tbxUnixPath.Text = nodes[i].Attributes["LOC"].Value; break; } } MessageBox.Show("Success"); } } } client.Disconnect(); } } catch (Ssh.Common.SshAuthenticationException) { MessageBox.Show("Failed to authenticate to server. Check username and password."); } catch (Exception) { MessageBox.Show("Unknown error."); } }
// // // // //int connect; //connect degiskeninini simdilik kullanmiyoruz.. //baglanma fonksiyonu tanimlamasi public void baglan() { ssh = new SshClient("10.141.3.110", "root", "ismail"); try { ssh = new SshClient("10.141.3.110", "root", "ismail"); ssh.Connect(); status = true; //connect = 1; } catch { status = false; tl.LogMessage("hata", "baglanti hatasi, tekrar deneyin.. [uc kapak getirene bardak hediye..]"); //connect = 0; } if(status==true) { try { stream = ssh.CreateShellStream("xterm", 80, 50, 1024, 1024, 1024); Thread.Sleep(100); stream.WriteLine("telnet localhost 6571"); Thread.Sleep(100); kontrol(); } catch { } } }
//выполнение команд в привилегированном режиме private void ExecuteEnableModeCommands(SshClient sshClient, List<string> commands) { using (ShellStream client = sshClient.CreateShellStream("terminal", 80, 24, 800, 600, 1024)) { SendCommandLF("enable", client);//переходим в привилегированный режим SendCommand(_host.enablePassword, client);//подтверждаем наши права foreach (string command in commands) { _listResult.Add(SendCommand(command, client)); } //Console.WriteLine("4 [" + SendCommand("terminal pager 0", client) + "]"); //Console.WriteLine("3 [" + SendCommand("show version", client) + "]"); //Console.WriteLine("5 [" + SendCommand("show run", client) + "]"); //Console.WriteLine("1 [" + SendCommandW("show interface ?", client) + "]"); } }
public SSHConnection(string host, string username) { this._host = host; this._username = username; _ssh = new SshClient(_host, _username, Passwords.FetchPassword(_host, _username)); _ssh.Connect(); _stream = _ssh.CreateShellStream("commands", 240, 200, 132, 80, 240 * 200); // Next job, wait until we get a command prompt _stream.WriteLine("# this is a test"); DumpTillFind(_stream, "# this is a test"); _prompt = _stream.ReadLine(); }
static void Main(string[] args) { client = new SshClient("130.18.14.67", "", ""); client.Connect(); stream = client.CreateShellStream(@"xterm", 80, 24, 800, 600, 2048); string cmd = ""; //flush buffer stream.Flush(); while(true) { stream.DataReceived += StartAsyncRead; Console.WriteLine("Logged in success!: "); cmd = Console.ReadLine(); stream.WriteLine(cmd); } }