Creating a forwarded port within an SSH tunnel

佐手、 提交于 2019-11-27 23:37:36

By changing the parameters of ForwardedPortLocal to:

    var port = new ForwardedPortLocal("localhost", 3306, "localhost", 3306);

(to make it explicit which interface I was binding to), and adding the following code in just before port.Start();:

    port.RequestReceived += delegate(object sender, PortForwardEventArgs e)
    {
        Console.WriteLine(e.OriginatorHost + ":" + e.OriginatorPort);
    };

I noticed the following being output:

    ::1:60309

The e.OriginatorHost part of this was ::1, which is the IPv6 equivalent of localhost; however, the destination server was using IPv4. Changing the parameters to:

    var port = new ForwardedPortLocal("127.0.0.1", 3306, "localhost", 3306);

forced the tunnel to run over IPv4 instead, and my code then worked exactly as I'd expected it to.

Stéphane Gourichon

After hitting the same problem and analyzing it, and considering I came to the conclusion that it is a bug (though it might be considered arguable, clearly the behavior surprises users of SSH.NET API).

So I reported it on Unexpected behavior (a.k.a. bug) on local tunnel · Issue #117 · sshnet/SSH.NET · GitHub.

Until it is fixed, the workaround in c# - Creating a forwarded port within an SSH tunnel - Stack Overflow works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!