J'aimerais creer un tunnel/proxy rdp pour me permettre de me connecter a un windows server avec mstsc. Le but est de taper 127.0.0.1:3389 dans mstsc et que le tunnel/proxy fasse la redirection. J'ai déjà codé un tunnel ssh le tunnel rdp ne fonctionne pas
using Renci.SshNet;
class SshTunnel : Tunnel
{
SshClient client;
public SshTunnel(SshTarget sshTarget) : base(sshTarget)
{
target = sshTarget;
}
public SshTunnel(string remoteHost, uint remotePort, string sshUsername, string sshPassword)
{
target = new SshTarget(remoteHost, remotePort, sshUsername, sshPassword);
}
public void start()
{
client = new SshClient(target.remoteHost, (int)target.remotePort, target.sshUsername, target.sshPassword);
client.Connect();
Console.WriteLine("SSH connection established.");
var portForwarded = new ForwardedPortLocal(localHost, localPort, target.remoteHost, target.remotePort);
client.AddForwardedPort(portForwarded);
portForwarded.Start();
}
public void sendCommand(string cmd)
{
using (var sshCmd = client.CreateCommand(cmd))
{
var result = sshCmd.Execute();
Console.WriteLine($"Command Result:\n{result}");
}
}
public void closeTunnel()
{
if (client.IsConnected)
{
client.Disconnect();
}
Console.WriteLine("end tunnel");
}
~SshTunnel()
{
if (client.IsConnected)
{
client.Disconnect();
}
Console.WriteLine("end tunnel");
}
}
class Target
{
public string remoteHost { get; }
public uint remotePort { get; }
public string sshUsername { get; }
public string sshPassword { get; }
public Target(String remoteHost, uint remotePort, string sshUsername, string sshPassword)
{
this.remoteHost = remoteHost;
this.remotePort = remotePort;
this.sshUsername = sshUsername;
this.sshPassword = sshPassword;
}
}
class Program
{
static void Main()
{
SshTarget st = new SshTarget("192.168.30.229", 3389, "administrateur", "pass");
SshTunnel tunnel = new SshTunnel(st);
tunnel.start();
Console.WriteLine("Press 'Q' to quit.");
while (Console.ReadKey().Key != ConsoleKey.Q)
{
// Keep the program running until 'Q' is pressed
}
}
}
tunnel RDP
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.