public List <Linux.CPUInfo> GetCPUInfos() { List <Linux.CPUInfo> cpus = new List <Linux.CPUInfo>(); Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection(); //using (Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection(SSHConnection)) { //if (sshClient.IsConnected) { foreach (Linux.CPUInfo ci in Linux.CPUInfo.GetCurrentCPUPerc(sshClient, MSSampleDelay)) { if (UseOnlyTotalCPUvalue && ci.IsTotalCPU) { cpus.Add(ci); } else if (!UseOnlyTotalCPUvalue) { cpus.Add(ci); } } } SSHConnection.CloseConnection(); } return(cpus); }
private void cmdTest_Click(object sender, EventArgs e) { try { string machineName = ApplyConfigVarsOnField(txtMachineName.Text); string userName = ApplyConfigVarsOnField(txtUsername.Text); string password = ApplyConfigVarsOnField(txtPassword.Text); string privateKeyFile = ApplyConfigVarsOnField(txtPrivateKeyFile.Text); string passPhrase = ApplyConfigVarsOnField(txtPassPhrase.Text); using (Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection( optPrivateKey.Checked ? SSHSecurityOption.PrivateKey : optPassword.Checked?SSHSecurityOption.Password: SSHSecurityOption.KeyboardInteractive, machineName, (int)sshPortNumericUpDown.Value, userName, password, privateKeyFile, passPhrase)) { if (sshClient.IsConnected) { MessageBox.Show(string.Format("Success\r\n{0}", sshClient.RunCommand("cat /proc/version").Result), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } sshClient.Disconnect(); } } catch (Exception ex) { MessageBox.Show(string.Format("Fail!\r\n{0}", ex.Message), "Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static List <CPUInfo> GetCurrentCPUPerc(Renci.SshNet.SshClient sshClient, int delayMS = 1000) { List <CPUInfo> cpuDiffs = new List <CPUInfo>(); List <CPUInfo> cpus1 = FromProcStat(sshClient.RunCommand("cat /proc/stat").Result); TH.Thread.Sleep(delayMS); List <CPUInfo> cpus2 = FromProcStat(sshClient.RunCommand("cat /proc/stat").Result); foreach (CPUInfo c1 in cpus1) { CPUInfo c2 = cpus2.FirstOrDefault(c => c.Name == c1.Name); if (c2 != null) { CPUInfo cpuUsageDiff = new CPUInfo(); cpuUsageDiff.Name = c1.Name; cpuUsageDiff.IsTotalCPU = c1.IsTotalCPU; cpuUsageDiff.User = c2.User - c1.User; cpuUsageDiff.Nice = c2.Nice - c1.Nice; cpuUsageDiff.System = c2.System - c1.System; cpuUsageDiff.Idle = c2.Idle - c1.Idle; cpuUsageDiff.IOWait = c2.IOWait - c1.IOWait; cpuUsageDiff.IRQ = c2.IRQ - c1.IRQ; cpuUsageDiff.SoftIRQ = c2.SoftIRQ - c1.SoftIRQ; cpuDiffs.Add(cpuUsageDiff); } } return(cpuDiffs); }
public static Renci.SshNet.SshClient GetSSHConnection(SSHSecurityOption sshSecurityOption, string machineName, int sshPort, string userName, string password, string privateKeyFile, string passCodeOrPhrase) { Renci.SshNet.SshClient sshClient; if (sshSecurityOption == SSHSecurityOption.Password) { byte[] b = System.Text.UTF8Encoding.UTF8.GetBytes(password.ToCharArray()); Renci.SshNet.AuthenticationMethod am = new Renci.SshNet.PasswordAuthenticationMethod(userName, b); Renci.SshNet.ConnectionInfo ci = new Renci.SshNet.ConnectionInfo(machineName, sshPort, userName, am); sshClient = new Renci.SshNet.SshClient(ci); } else if (sshSecurityOption == SSHSecurityOption.PrivateKey) { Renci.SshNet.PrivateKeyFile[] pkf = new Renci.SshNet.PrivateKeyFile[1]; pkf[0] = new Renci.SshNet.PrivateKeyFile(privateKeyFile, passCodeOrPhrase); Renci.SshNet.PrivateKeyAuthenticationMethod pm = new Renci.SshNet.PrivateKeyAuthenticationMethod(userName, pkf); Renci.SshNet.ConnectionInfo ci = new Renci.SshNet.ConnectionInfo(machineName, sshPort, userName, pm); sshClient = new Renci.SshNet.SshClient(ci); } else { Renci.SshNet.KeyboardInteractiveAuthenticationMethod kauth = new Renci.SshNet.KeyboardInteractiveAuthenticationMethod(userName); Renci.SshNet.PasswordAuthenticationMethod pauth = new Renci.SshNet.PasswordAuthenticationMethod(userName, password); keyBoardPassword = password; kauth.AuthenticationPrompt += new EventHandler <Renci.SshNet.Common.AuthenticationPromptEventArgs>(HandleKeyEvent); sshClient = new Renci.SshNet.SshClient(new Renci.SshNet.ConnectionInfo(machineName, sshPort, userName, pauth, kauth)); } if (machineName.Trim().Length > 0) { sshClient.Connect(); } return(sshClient); }
public void Dispose() { ssh?.Dispose(); scp?.Dispose(); ssh = null; scp = null; }
private void RefreshList() { try { cmdOK.Enabled = false; Renci.SshNet.SshClient sshClient = QuickMon.Linux.SshClientTools.GetSSHConnection(SSHConnectionDetails); lvwProcesses.Items.Clear(); foreach (QuickMon.Linux.ProcessInfo process in QuickMon.Linux.ProcessInfo.FromPsAux(sshClient).OrderBy(p => p.ProcessName)) { if (txtFilter.Text.Trim().Length == 0 || process.ProcessName.ToLower().Contains(txtFilter.Text.ToLower())) { ListViewItem lvi = new ListViewItem(process.ProcessName); lvi.SubItems.Add(process.percCPU.ToString("0.0")); lvi.SubItems.Add(process.percMEM.ToString("0.0")); lvi.Tag = process; lvwProcesses.Items.Add(lvi); } } cmdOK.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public void Should_Successfully_To_And_Login_With_New_Password() { Assert.Inconclusive("SshClient cannot be used from assemblies with strong names."); #if false bool sucess = false; for (int i = 0; i < 10; i++) { using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", NewPassword)) { client.Connect(); sucess = client.IsConnected; if (sucess) { break; } } Thread.Sleep(1000); } Assert.IsTrue(sucess); #endif }
public void Close() { try { ssh?.Disconnect(); } catch { } try { scp?.Disconnect(); } catch { } ssh = null; scp = null; }
public static List <NicInfo> GetCurrentNicStats(Renci.SshNet.SshClient sshClient, int delayMS = 1000) { List <NicInfo> nicDiffs = new List <NicInfo>(); List <NicInfo> nics1 = FromIfconfig(sshClient.RunCommand("ifconfig").Result); TH.Thread.Sleep(delayMS); List <NicInfo> nics2 = FromIfconfig(sshClient.RunCommand("ifconfig").Result); foreach (NicInfo c1 in nics1) { NicInfo c2 = nics2.FirstOrDefault(c => c.Name == c1.Name); if (c2 != null) { NicInfo nicUsageDiff = new NicInfo(); nicUsageDiff.MeasurementDelayMS = delayMS; nicUsageDiff.Name = c1.Name; nicUsageDiff.LocalLoopback = c1.LocalLoopback; nicUsageDiff.IpV4 = c1.IpV4; nicUsageDiff.IpV6 = c1.IpV6; nicUsageDiff.HWAddress = c1.HWAddress; nicUsageDiff.RxBytes = c2.RxBytes - c1.RxBytes; nicUsageDiff.TxBytes = c2.TxBytes - c1.TxBytes; nicDiffs.Add(nicUsageDiff); } } return(nicDiffs); }
public CcmBridge(string name, string ipPrefix, bool instantiateSshClient = false) { Name = name; IpPrefix = ipPrefix; CcmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); if (instantiateSshClient) { string sshHost = "TBD"; int sshPort = -1; string sshUser = "******"; string sshPassword = "******"; _sshClient = new Renci.SshNet.SshClient(sshHost, sshPort, sshUser, sshPassword); _sshClient.Connect(); _sshShellStream = _sshClient.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_sshShellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) { break; } } } }
public ISshSession Create(RouterCredentials credentials) { var sshClient = new Renci.SshNet.SshClient(credentials.Host, credentials.User, credentials.Password); sshClient.Connect(); return(new SshSession(sshClient, credentials.User)); }
public void Dispose() { if (_ssh_client != null) { _ssh_client.Disconnect(); _ssh_client = null; } }
public void Dispose() { if (_sshClient != null) { _sshClient.Disconnect(); _sshClient = null; } }
public void CloseConnection(bool force = false) { if (currentConnection != null && (!Persistent || force)) { currentConnection.Disconnect(); currentConnection = null; } }
public List <ProcessInfoState> GetStates() { List <ProcessInfoState> processEntries = new List <ProcessInfoState>(); Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection(); LinuxProcessSubEntry globalAlertDef = new LinuxProcessSubEntry(); globalAlertDef.CPUPercWarningValue = CPUPercWarningValue; globalAlertDef.CPUPercErrorValue = CPUPercErrorValue; globalAlertDef.MemPercWarningValue = MemPercWarningValue; globalAlertDef.MemPercErrorValue = MemPercErrorValue; List <ProcessInfo> runningProcesses = ProcessInfo.FromPsAux(sshClient); if (ProcessCheckOption == ProcessCheckOption.TopXByCPU) { foreach (ProcessInfo p in (from p in runningProcesses orderby p.percCPU descending select p).Take(TopProcessCount)) { processEntries.Add(new ProcessInfoState() { ProcessInfo = p, AlertDefinition = globalAlertDef }); } } else if (ProcessCheckOption == ProcessCheckOption.TopXByMem) { foreach (ProcessInfo p in (from p in runningProcesses orderby p.percMEM descending select p).Take(TopProcessCount)) { processEntries.Add(new ProcessInfoState() { ProcessInfo = p, AlertDefinition = globalAlertDef }); } } else { foreach (ProcessInfo p in runningProcesses) { LinuxProcessSubEntry se = (from LinuxProcessSubEntry sdef in SubItems where FileNameMatch(p.ProcessName, sdef.ProcessName) select sdef).FirstOrDefault(); if (se != null) { processEntries.Add(new ProcessInfoState() { ProcessInfo = p, AlertDefinition = se }); } } } SSHConnection.CloseConnection(); return(processEntries); }
private void RestartController(object mSender, EventArgs e) { Task.Run(() => { string IP = ""; string Building = ""; string Room = ""; string Tag = ""; Task.Run(() => { Button sender = (Button)mSender; IP = RoomIPs[sender.Id]; Building = ((MainPage)Application.Current.MainPage)._Controllers.FindByIP(IP).Building; Room = ((MainPage)Application.Current.MainPage)._Controllers.FindByIP(IP).Room; Tag = ((MainPage)Application.Current.MainPage)._Controllers.FindByIP(IP).Tag; }); using (Renci.SshNet.SshClient sshClient = new Renci.SshNet.SshClient(IP, "Username", "Password")) { sshClient.HostKeyReceived += (_sender, _e) => { _e.CanTrust = true; }; sshClient.ConnectionInfo.Timeout = TimeSpan.FromSeconds(30); try { sshClient.Connect(); } catch { return; } var amxStream = sshClient.CreateShellStream("amxStream", 0, 0, 0, 0, 256); bool streamLockToken = true; var streamTTL = DateTime.Now.Add(TimeSpan.FromSeconds(30)); while (streamLockToken) { if (amxStream.DataAvailable) { streamLockToken = false; } else if (DateTime.Now >= streamTTL) { sshClient.Disconnect(); return; } else { System.Threading.Thread.Sleep(0); } } amxStream.WriteLine("reboot"); sshClient.Disconnect(); } }); }
public MemInfo GetMemoryInfo() { MemInfo mi = new MemInfo(); Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection(); mi = MemInfo.FromCatProcMeminfo(sshClient); SSHConnection.CloseConnection(); return(mi); }
public void Should_Successfully_To_And_Login_With_Old_Password() { using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", _newTestServer.AdminPassword)) { client.Connect(); Assert.IsTrue(client.IsConnected); } }
private void lblAutoAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { SSHConnectionDetails sshConnection = sshConnectionDetails.Clone(); sshConnection.ComputerName = ApplyConfigVarsOnField(sshConnection.ComputerName); sshConnection.UserName = ApplyConfigVarsOnField(sshConnection.UserName); sshConnection.Password = ApplyConfigVarsOnField(sshConnection.Password); sshConnection.PrivateKeyFile = ApplyConfigVarsOnField(sshConnection.PrivateKeyFile); sshConnection.PassPhrase = ApplyConfigVarsOnField(sshConnection.PassPhrase); sshConnection.ConnectionName = ApplyConfigVarsOnField(sshConnection.ConnectionName); sshConnection.ConnectionString = ApplyConfigVarsOnField(sshConnection.ConnectionString); if (lvwNICs.Items.Count > 0 && (MessageBox.Show("Clear all existing entries?", "Clear", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)) { return; } else { lvwNICs.Items.Clear(); lvwNICs.Items.Add(new ListViewItem("Querying " + sshConnection.ComputerName + "...")); Application.DoEvents(); } Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection(sshConnection); if (sshClient.IsConnected) { lvwNICs.Items.Clear(); foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient)) { NIXNICSubEntry dsse = new NIXNICSubEntry() { NICName = di.Name, WarningValueKB = (long)warningNumericUpDown.Value, ErrorValueKB = (long)errorNumericUpDown.Value }; ListViewItem lvi = new ListViewItem() { Text = dsse.NICName }; lvi.SubItems.Add(dsse.WarningValueKB.ToString()); lvi.SubItems.Add(dsse.ErrorValueKB.ToString()); lvi.Tag = dsse; lvwNICs.Items.Add(lvi); } } else { lvwNICs.Items.Clear(); MessageBox.Show("Could not connect to computer!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public override MonitorState GetCurrentState() { MonitorState currentState = new MonitorState() { ForAgent = Description, State = CollectorState.NotAvailable, CurrentValueUnit = "%" }; try { MemInfo mi = new MemInfo(); Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection(); mi = MemInfo.FromCatProcMeminfo(sshClient); SSHConnection.CloseConnection(); double outputValue = 0; if (MemoryType == LinuxMemoryType.MemAvailable) { outputValue = mi.AvailablePerc; if (outputValue == 0 && mi.TotalKB > 0) { outputValue = (mi.FreeKB + mi.Buffers + mi.Cached) / mi.TotalKB; } } else if (MemoryType == LinuxMemoryType.MemFree) { outputValue = mi.FreePerc; } else { outputValue = mi.SwapFreePerc; } currentState.CurrentValue = outputValue.ToString("0.0"); if (ErrorValue >= outputValue) { currentState.State = CollectorState.Error; } else if (WarningValue >= outputValue) { currentState.State = CollectorState.Warning; } else { currentState.State = CollectorState.Good; } } catch (Exception ex) { currentState.State = CollectorState.Error; currentState.RawDetails = ex.Message; } return(currentState); }
private Renci.SshNet.SshClient GetSshClient() { if (ssh == null) { ssh = new Renci.SshNet.SshClient(host, user, GetKeyFiles()); } if (!ssh.IsConnected) { ssh.Connect(); } return(ssh); }
public void Should_Successfully_To_And_Login_With_Old_Password() { Assert.Inconclusive("SshClient cannot be used from assemblies with strong names."); #if false using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", _newTestServer.AdminPassword)) { client.Connect(); Assert.IsTrue(client.IsConnected); } #endif }
// runs multiple commands on the server public bool runCommands(string[] commands) { Renci.SshNet.SshCommand sshCommand; Renci.SshNet.SshClient sshClient = new Renci.SshNet.SshClient(this.ipAddress, 8888, this.username, this.password); sshClient.Connect(); foreach (string s in commands) { sshCommand = sshClient.RunCommand(s); Thread.Sleep(100); } sshClient.Disconnect(); return(true); }
public List <DiskInfoState> GetDiskInfos() { List <DiskInfoState> fileSystemEntries = new List <DiskInfoState>(); Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection(); //First see if ANY subentry is for all bool addAll = (from LinuxDiskSpaceSubEntry d in SubItems where d.FileSystemName == "*" select d).Count() > 0; if (addAll) { LinuxDiskSpaceSubEntry alertDef = (from LinuxDiskSpaceSubEntry d in SubItems where d.FileSystemName == "*" select d).FirstOrDefault(); foreach (Linux.DiskInfo di in DiskInfo.FromDfTk(sshClient)) { DiskInfoState dis = new DiskInfoState() { FileSystemInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef }; fileSystemEntries.Add(dis); } } else { foreach (Linux.DiskInfo di in DiskInfo.FromDfTk(sshClient)) { LinuxDiskSpaceSubEntry alertDef = (from LinuxDiskSpaceSubEntry d in SubItems where d.FileSystemName.ToLower() == di.Name.ToLower() select d).FirstOrDefault(); if (alertDef != null) { if (!fileSystemEntries.Any(f => f.FileSystemInfo.Name.ToLower() == di.Name.ToLower())) { DiskInfoState dis = new DiskInfoState() { FileSystemInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef }; fileSystemEntries.Add(dis); } } } } SSHConnection.CloseConnection(); return(fileSystemEntries); }
public List <NICState> GetNICInfos() { List <NICState> nicEntries = new List <NICState>(); Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection(); //First see if ANY subentry is for all bool addAll = (from LinuxNICSubEntry d in SubItems where d.NICName == "*" select d).Count() > 0; if (addAll) { LinuxNICSubEntry alertDef = (from LinuxNICSubEntry d in SubItems where d.NICName == "*" select d).FirstOrDefault(); foreach (Linux.NicInfo ni in NicInfo.GetCurrentNicStats(sshClient, 250)) { NICState nis = new NICState() { NICInfo = ni, State = CollectorState.NotAvailable, AlertDefinition = alertDef }; nicEntries.Add(nis); } } else { foreach (Linux.NicInfo di in NicInfo.GetCurrentNicStats(sshClient, 250)) { LinuxNICSubEntry alertDef = (from LinuxNICSubEntry d in SubItems where d.NICName.ToLower() == di.Name.ToLower() select d).FirstOrDefault(); if (alertDef != null) { if (!nicEntries.Any(f => f.NICInfo.Name.ToLower() == di.Name.ToLower())) { NICState dis = new NICState() { NICInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef }; nicEntries.Add(dis); } } } SSHConnection.CloseConnection(); } return(nicEntries); }
private CCMBridge() { _ccmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); _ssh_client = new Renci.SshNet.SshClient(Options.Default.SSH_HOST, Options.Default.SSH_PORT, Options.Default.SSH_USERNAME, Options.Default.SSH_PASSWORD); _ssh_client.Connect(); _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_ssh_shellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) break; } }
private CCMBridge() { _ccmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); _ssh_client = new Renci.SshNet.SshClient(_ssh_host, _ssh_port, _ssh_username, _ssh_password); _ssh_client.Connect(); _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_ssh_shellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) break; } }
private string RunCommand(Renci.SshNet.SshClient ssh, string line) { var resultStr = string.Empty; var cmd = ssh.RunCommand(line); if (!string.IsNullOrWhiteSpace(cmd.Error)) { resultStr += cmd.Error; } else { resultStr += cmd.Result; } return(resultStr); }
private string OpenAndRunCommand() { Renci.SshNet.SshClient ssh = new Renci.SshNet.SshClient("119.23.71.29", "root", "Zyp885299"); ssh.Connect(); var resultStr = string.Empty; resultStr = $"{resultStr}\r\n{RunCommand(ssh, "whoami")}"; resultStr = $"{resultStr}\r\n{RunCommand(ssh, "ls")}"; resultStr = $"{resultStr}\r\n{RunCommand(ssh, "ps")}"; resultStr = $"{resultStr}\r\n{RunCommand(ssh, "top")}"; resultStr = $"{resultStr}\r\n{RunCommand(ssh, "pwd")}"; resultStr = $"{resultStr}\r\n{RunCommand(ssh, "exit")}"; // ssh.Disconnect(); return(resultStr); }
public override MonitorState GetCurrentState() { MonitorState currentState = new MonitorState() { ForAgent = Description, State = CollectorState.Good, CurrentValueUnit = "%" }; try { Renci.SshNet.SshClient sshConnection = SSHConnection.GetConnection(); List <CPUInfo> cpuInfos = CPUInfo.GetCurrentCPUPerc(sshConnection, MSSampleDelay); SSHConnection.CloseConnection(); currentState.State = CollectorState.NotAvailable; if (cpuInfos.Count > 0) { currentState.CurrentValue = cpuInfos[0].CPUPerc.ToString("0.0"); currentState.State = GetState(cpuInfos[0].CPUPerc); } for (int i = 1; i < cpuInfos.Count; i++) { CollectorState currentCPUState = GetState(cpuInfos[i].CPUPerc); if ((int)currentCPUState > (int)currentState.State && !UseOnlyTotalCPUvalue) { currentState.CurrentValue = cpuInfos[i].CPUPerc.ToString("0.0"); currentState.State = currentCPUState; } MonitorState cpuState = new MonitorState() { ForAgent = cpuInfos[i].Name, State = currentCPUState, CurrentValue = cpuInfos[i].CPUPerc.ToString("0.0"), CurrentValueUnit = "%" }; currentState.ChildStates.Add(cpuState); } } catch (Exception wsException) { currentState.State = CollectorState.Error; currentState.RawDetails = wsException.Message; } return(currentState); }
// Brute SSH public static void SSH(string host, string username, string password) { var SSH = new Renci.SshNet.SshClient(host, username, password); try { SSH.Connect(); SSH.Disconnect(); core.Exit("[SSH] Logged in", output); } catch { output.error = true; core.Exit("[SSH] Failed to login", output); } finally { SSH.Dispose(); } }
private void lblAutoAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { if (lvwDisks.Items.Count > 0 && (MessageBox.Show("Clear all existing entries?", "Clear", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)) { return; } else { lvwDisks.Items.Clear(); lvwDisks.Items.Add(new ListViewItem("Querying " + sshConnectionDetails.ComputerName + "...")); Application.DoEvents(); } Renci.SshNet.SshClient sshClient = QuickMon.Linux.SshClientTools.GetSSHConnection(sshConnectionDetails); if (sshClient.IsConnected) { lvwDisks.Items.Clear(); foreach (Linux.DiskIOInfo di in QuickMon.Linux.DiskIOInfo.GetCurrentDiskStats(sshClient)) { LinuxDiskIOSubEntry dsse = new LinuxDiskIOSubEntry() { Disk = di.Name, WarningValue = (double)warningNumericUpDown.Value, ErrorValue = (double)errorNumericUpDown.Value }; ListViewItem lvi = new ListViewItem() { Text = dsse.Disk }; lvi.SubItems.Add(dsse.WarningValue.ToString()); lvi.SubItems.Add(dsse.ErrorValue.ToString()); lvi.Tag = dsse; lvwDisks.Items.Add(lvi); } } else { lvwDisks.Items.Clear(); MessageBox.Show("Could not connect to computer!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public ListResult GetListResult() { var host = Host; var username = Username; var password = Password; using (var sshClient = new Renci.SshNet.SshClient(host, username, password)) { sshClient.Connect(); var cmd = sshClient.CreateCommand("tdtool --list", Encoding.UTF8); var commandResult = cmd.Execute(); var listDeserializer = new ListDeserializer(new SensorListDeserializer()); var result = listDeserializer.Deserialize(commandResult); return result; } }
private CCMBridge() { _ccmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); _ssh_client = new Renci.SshNet.SshClient(Options.Default.SSH_HOST, Options.Default.SSH_PORT, Options.Default.SSH_USERNAME, Options.Default.SSH_PASSWORD); _ssh_client.Connect(); _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_ssh_shellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) { break; } } }
public CcmBridge(string name, string ipPrefix, bool instantiateSshClient = false) { Name = name; IpPrefix = ipPrefix; CcmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); if (instantiateSshClient) { string sshHost = "TBD"; int sshPort = -1; string sshUser = "******"; string sshPassword = "******"; _sshClient = new Renci.SshNet.SshClient(sshHost, sshPort, sshUser, sshPassword); _sshClient.Connect(); _sshShellStream = _sshClient.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_sshShellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) break; } } }
public void Should_Successfully_To_And_Login_With_New_Password() { var provider = new CloudServersProvider(_testIdentity); var serverDetails = provider.GetDetails(_testServer.Id); bool sucess = false; for (int i = 0; i < 10; i++) { using (var client = new Renci.SshNet.SshClient(serverDetails.AccessIPv4, "root", NewPassword)) { client.Connect(); sucess = client.IsConnected; if (sucess) break; } Thread.Sleep(1000); } Assert.IsTrue(sucess); }
public void Test025_Should_Successfully_To_And_Login_With_New_Password() { var provider = new net.openstack.Providers.Rackspace.ComputeProvider(); var serverDetails = provider.GetDetails(_testIdentity, _testServer.Id); using(var client = new Renci.SshNet.SshClient(serverDetails.AccessIPv4, "root", NewPassword)) { client.Connect(); Assert.IsTrue(client.IsConnected); } }
public void Should_Successfully_To_And_Login_With_Old_Password() { var provider = new CloudServersProvider(_testIdentity); var serverDetails = provider.GetDetails(_testServer.Id); using (var client = new Renci.SshNet.SshClient(serverDetails.AccessIPv4, "root", _testServer.AdminPassword)) { client.Connect(); Assert.IsTrue(client.IsConnected); } }
public void Should_Successfully_To_And_Login_With_New_Password() { bool sucess = false; for (int i = 0; i < 10; i++) { using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", NewPassword)) { client.Connect(); sucess = client.IsConnected; if (sucess) break; } Thread.Sleep(1000); } Assert.IsTrue(sucess); }
public void Should_Successfully_To_And_Login_With_New_Password() { Assert.Inconclusive("SshClient cannot be used from assemblies with strong names."); #if false bool sucess = false; for (int i = 0; i < 10; i++) { using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", NewPassword)) { client.Connect(); sucess = client.IsConnected; if (sucess) break; } Thread.Sleep(1000); } Assert.IsTrue(sucess); #endif }