Пример #1
0
        private void Connect(string hostname, string user, string pass, string private_key_file)
        {
            SSHConnectionParameter f = new SSHConnectionParameter();

            f.UserName = user;
            f.Password = pass;
            f.Protocol = Routrek.SSHC.SSHProtocol.SSH2;

            if (string.IsNullOrWhiteSpace(private_key_file))
            {
                f.AuthenticationType = Routrek.SSHC.AuthenticationType.Password;
            }
            else
            {
                f.AuthenticationType = Routrek.SSHC.AuthenticationType.PublicKey;
                f.IdentityFile       = private_key_file;
            }
            f.WindowSize = 0x1000;
            f.Protocol   = SSHProtocol.SSH2;

            Socket    s  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ip = Dns.GetHostEntry(hostname).AddressList[0]; // Dns.GetHostByName(hostname).AddressList[0];

            s.Connect(new IPEndPoint(ip, 22));
            _conn = Routrek.SSHC.SSHConnection.Connect(f, reader, s);

            Routrek.SSHC.SSHChannel ch = _conn.OpenShell(reader);
            ch.ResizeTerminal(80, 24, 14, 14);
            reader._pf = ch;
            Routrek.SSHC.SSHConnectionInfo ci = _conn.ConnectionInfo;


            if (!eReadyToRoll.WaitOne(60000))
            {
                //prompt not received
                throw new Exception("Connected to the target OK, but have not received the clear command prompt ($ or #).");
            }

            isOpen = true;
        }
Пример #2
0
        /// <summary>
        /// Method to connect to the Wabis machine
        /// </summary>
        /// <returns>true if connected else false</returns>
        public bool Connect()
        {
            connParameter.Protocol           = Routrek.SSHC.SSHProtocol.SSH2;
            connParameter.AuthenticationType = AuthenticationType.Password;
            connParameter.WindowSize         = 0x1000;
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);

            try
            {
                s.Connect(new IPEndPoint(_ipAddress, 22));
            }
            catch
            {
                s.Close();
                return(false);
            }

            try
            {
                _conn             = SSHConnection.Connect(connParameter, reader, s);
                reader.connection = _conn;
                Routrek.SSHC.SSHChannel ch = _conn.OpenShell(reader);
                reader.Channel = ch;
                SSHConnectionInfo ci = _conn.ConnectionInfo;
                reader.notify += new RcvdData(PrintResult);
                if (_conn.AuthenticationResult.ToString() == "Success")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception connectionException)
            {
                Framework.Logger.LogError("Fail to connect to SSH Server, error: " + connectionException.Message);
                throw connectionException;
            }
        }
Пример #3
0
 public void EstablishPortforwarding(Routrek.SSHC.ISSHChannelEventReceiver rec, Routrek.SSHC.SSHChannel channel)
 {
     _pf = channel;
 }
        protected ChannelEntry RegisterChannelEventReceiver(SSHChannel ch, ISSHChannelEventReceiver r)
        {
            lock(this) {
                ChannelEntry e = new ChannelEntry();
                e._channel = ch;
                e._receiver = r;
                e._localID = _channel_sequence++;

                for(int i=0; i<_channel_entries.Count; i++) {
                    if(_channel_entries[i]==null) {
                        _channel_entries[i] = e;
                        return e;
                    }
                }
                _channel_entries.Add(e);
                return e;
            }
        }
 internal void RegisterChannel(int local_id, SSHChannel ch)
 {
     FindChannelEntry(local_id)._channel = ch;
 }
Пример #6
0
 public void EstablishPortforwarding(Routrek.SSHC.ISSHChannelEventReceiver rec, Routrek.SSHC.SSHChannel channel)
 {
     _pf = channel;
 }
Пример #7
0
        public void start()
        {
            try
            {
                SSHConnectionParameter f = new SSHConnectionParameter();
                f.UserName = userName;

                f.Password = passwordWord;
                f.Protocol = SSHProtocol.SSH2;
                f.AuthenticationType = AuthenticationType.Password;
                f.WindowSize = 0x1000;
                _objTmp = new Dictionary<TextBox, StringBuilder>();
                Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                //s.Blocking = false;
                s.Connect(new IPEndPoint(IPAddress.Parse(ip), _port));

                _conn = SSHConnection.Connect(f, this, s);

                this._conn = _conn;

                SSHChannel ch = _conn.OpenShell(this);
                this._pf = ch;
                _linePool = new List<string>();
                SSHConnectionInfo ci = _conn.ConnectionInfo;
            }
            catch (Exception e1)
            {
                SetText(_objTmp, form.consoleBox, e1.Message);
            }
        }
Пример #8
0
 public void EstablishPortforwarding(ISSHChannelEventReceiver rec, SSHChannel channel)
 {
     _pf = channel;
 }