I have to access the database in MySQL that is on the computer with IP (1.1.1.1) with an external network.
I created a tunnel with SSH.NET, but I can't access the IP (1.1.1.1) of the computer where the database is located in MySQL.
Up to the Public IP the tunnel seems to work, but I can't access the Computer IP (1.1.1.1), since I didn't understand how SSH.NET works. Using PuTTY I enter the public IP of the port and in the SSH tunnel section I insert the IP computer (1.1.1.1) with port 3306 and it works very well. The code is this
using (var client = new SshClient("ip public", port, "user", "password"))
{
client.Connect();
if (client.IsConnected)
{
var portForwarded = new ForwardedPortLocal("127.0.0.1",22, "1.1.1.1",3306);
client.AddForwardedPort(portForwarded);
portForwarded.Start();
string db = @"Server=127.0.0.1;Port=3306;Database=xxx;Uid=root;Pwd=xxx;";
{
var mySQLCon = new MySqlConnection(db);
mySQLCon.Open();
if (mySQLCon.State == ConnectionState.Open)
{
MainWindow stx = new MainWindow(db);
stx.ShowDialog();
}
}
}
}
Am I wrong to put the parameters in ForwardedPortLocal
?
ForwardedPortLocal("127.0.0.1",22, "1.1.1.1",3306);
I wanted to know if I entered the parameters in ForwardedPortLocal
correctly, or where I am wrong in making tunnels with SSH.NET ...