Exemplo n.º 1
0
        //ConnectionInfo connectionInfo;

        #endregion

        #region Methods

        public override bool Open()
        {
            Ssh = new SshHelper.SshHelper()
            {
                Host               = Machine,
                UserName           = UserName,
                Password           = Password,
                SudoPassword       = Password,
                PrivateKeyFileName = PrivateKeyFileName
            };
            return(Ssh.CheckConnected);
        }
Exemplo n.º 2
0
        /// <summary>
        /// In progress...
        /// Get the operating system of specified machine. The credentials must be provided.
        /// For now it can identify Ubuntu, Debian and Windows
        /// </summary>
        /// <param name="machineName"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="privateKeyFileName"></param>
        /// <returns></returns>
        public static OperatingSystems GetMachineOs(string machineName, string userName, string password, string privateKeyFileName)
        {
            //TODO: This function did not detect Windows on localhost!
            var result = OperatingSystems.Unknown;
            var ssh    = new SshHelper.SshHelper()
            {
                Host               = machineName,
                UserName           = userName,
                Password           = password,
                PrivateKeyFileName = privateKeyFileName
            };
            var os = ssh.Exec("cat /etc/issue");

            if (!string.IsNullOrEmpty(os))
            {
                os = os.ToLower();
                if (os.IndexOf("ubuntu", StringComparison.Ordinal) >= 0 ||
                    os.IndexOf("debian", StringComparison.Ordinal) >= 0)
                {
                    result = OperatingSystems.Aptitude;
                }
            }
            else
            {
                var ws = new WindowsScanner(machineName, userName, password, null);
                if (!ws.Open())
                {
                    return(result);
                }
                ws.ScanWmiClass("Win32_OperatingSystem", (new[] { new Field {
                                                                      Name = "Name", MapTo = "Name"
                                                                  } }).ToList());
                if (ws.Result.Count > 0)
                {
                    result = OperatingSystems.Windows;
                }
            }
            return(result);
        }