Ejemplo n.º 1
0
        static bool ForwardPort()
        {
            try
            {
                Console.WriteLine("\r\n[PF] Trying port forwarding...\r\n");
                var portFwld = new ForwardedPortLocal("127.0.0.1", Convert.ToUInt32(3306), "127.0.0.1", Convert.ToUInt32(3306));

                Console.WriteLine("[PF] Bound Host : {0}:{1}", ((ForwardedPortLocal)portFwld).BoundHost, ((ForwardedPortLocal)portFwld).BoundPort);
                Console.WriteLine("[PF] Local Host : {0}:{1}\r\n", ((ForwardedPortLocal)portFwld).Host, ((ForwardedPortLocal)portFwld).Port);

                client.AddForwardedPort(portFwld);

                portFwld.Start();
                if (!portFwld.IsStarted)
                {
                    Console.WriteLine("[PF] Port forwarding has failed.\r\n");
                    Console.ReadLine();
                    return(false);
                }
                else
                {
                    Console.WriteLine("[PF] Port forwarded: {0}\r\n", portFwld.ToString());
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("[PF] Port Forwarding is ERROR !!\r\n\r\n[PF] Error Message : {0}\r\n[PF] Stack Trace : {1}\r\n", ex.Message, ex.StackTrace);
                return(false);
            }
        }
Ejemplo n.º 2
0
    // Only perform after Start() has been initially performed
    //Added object state to comply with threadpool requirements
    public void callUploadPlayerLogs(object state)
    {
        PasswordConnectionInfo connectionInfo = new PasswordConnectionInfo(remoteHost, remoteUser, remotePassword);

        connectionInfo.Timeout = TimeSpan.FromSeconds(30);

        using (var client = new SshClient(connectionInfo))
        {
            try
            {
                Debug.Log("Trying SSH connection...");
                client.Connect();
                if (client.IsConnected)
                {
                    Debug.Log("SSH connection is active: " + client.ConnectionInfo.ToString());
                }
                else
                {
                    Debug.Log("SSH connection has failed: " + client.ConnectionInfo.ToString());
                }

                Debug.Log("Trying port forwarding...");
                var portFwld = new ForwardedPortLocal(localHost, localPort, localHost, localPort);
                Debug.Log(portFwld.BoundHost);
                Debug.Log(portFwld.BoundPort);
                Debug.Log(portFwld.Host);
                Debug.Log(portFwld.Port);
                client.AddForwardedPort(portFwld);
                portFwld.Start();
                if (portFwld.IsStarted)
                {
                    Debug.Log("Port forwarded: " + portFwld.ToString());
                }
                else
                {
                    Debug.Log("Port forwarding has failed.");
                }

                Debug.Log("Trying database connection...");
                MySQL_Connector dbConnect = new MySQL_Connector(localHost, dbName, dbUser, dbPassword, remotePort);
                dbConnect.uploadIfSynced(SQLiteDatabase.getPlayer().is_synced);
                Debug.Log("Successfully Uploaded Player Logs!");
                //toast.showToastOnUiThread("Successfully Uploaded Player Logs!");
            }
            catch (SshException e)
            {
                Debug.Log("SSH client connection error: " + e.Message);
            }
            catch (System.Net.Sockets.SocketException e)
            {
                Debug.Log("Socket connection error: " + e.Message);
            }
        }
    }
        /*
         * public void Tooltip(ListControl lc)
         * {
         *  foreach (ListViewItem item in lc.)
         *  {
         *      item.ToolTipText = QuoteInformation[Convert.ToInt16(item.Text)];
         *  }
         * }
         */
        void sshConnection(Func <Boolean> function)
        {
            PasswordConnectionInfo connectionInfo = new PasswordConnectionInfo("stellarismysql.ddns.net", 7846, "gregyoung", "stellaris"); //replace "192.168.2.52" with "stellarismysql.ddns.net", 7846 for connections from offsite

            connectionInfo.Timeout = TimeSpan.FromSeconds(30);

            using (var client = new SshClient(connectionInfo))
            {
                try
                {
                    Console.WriteLine("Trying SSH connection...");
                    client.Connect();
                    if (client.IsConnected)
                    {
                        Console.WriteLine("SSH connection is active: {0}", client.ConnectionInfo.ToString());
                    }
                    else
                    {
                        Console.WriteLine("SSH connection has failed: {0}", client.ConnectionInfo.ToString());
                    }

                    Console.WriteLine("\r\nTrying port forwarding...");
                    var portFwld = new ForwardedPortLocal("127.0.0.1", 1000, "localhost", 3306);
                    client.AddForwardedPort(portFwld);
                    portFwld.Start();
                    if (portFwld.IsStarted)
                    {
                        Console.WriteLine("Port forwarded: {0}", portFwld.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Port forwarding has failed.");
                    }

                    function();

                    client.Disconnect();
                }
                catch (SshException err)
                {
                    Console.WriteLine("SSH client connection error: {0}", err.Message);
                }
                catch (System.Net.Sockets.SocketException err)
                {
                    Console.WriteLine("Socket connection error: {0}", err.Message);
                }
            }
        }
Ejemplo n.º 4
0
        public static void test3()
        {
            using (var client = new SshClient("219.245.64.4", "root", "123456"))
            {
                try
                {
                    Console.WriteLine("Trying SSH connection...");
                    client.Connect();
                    if (client.IsConnected)
                    {
                        Console.WriteLine("SSH connection is active: {0}", client.ConnectionInfo.ToString());
                    }
                    else
                    {
                        Console.WriteLine("SSH connection has failed: {0}", client.ConnectionInfo.ToString());
                    }

                    Console.WriteLine("\r\nTrying port forwarding...");
                    var port = new ForwardedPortLocal("127.0.0.1", Convert.ToUInt32(19999), "219.245.64.4", Convert.ToUInt32(3306));

                    //ForwardedPortDynamic port = new ForwardedPortDynamic("127.0.0.1", 3306);
                    client.AddForwardedPort(port);
                    port.Start();
                    if (port.IsStarted)
                    {
                        Console.WriteLine("Port forwarded: {0}", port.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Port forwarding has failed.");
                    }
                }
                catch (SshException e)
                {
                    Console.WriteLine("SSH client connection error: {0}", e.Message);
                }
                catch (System.Net.Sockets.SocketException e)
                {
                    Console.WriteLine("Socket connection error: {0}", e.Message);
                }
            }
        }