This project is read-only.

Dynamic PortForward Problem

Feb 28, 2013 at 3:22 PM
Edited Feb 28, 2013 at 3:57 PM
Hi, I'm using sshnet-22965 to build dynamic portforward application. The application runs fine except when when i use it with browser, it thrown "An invalid IP address was specified" exception for every site. and here is my code
 var listenport = new ForwardedPortDynamic("", Convert.ToUInt16(textBox8.Text));
            connectionInfo = new PasswordConnectionInfo(tbSSHHost.Text, int.Parse(tbSSHPort.Text), tbSSHUser.Text, tbSSHPassword.Text, ProxyTypes.Http, textBox7.Text, int.Parse(textBox6.Text)); 
            connectionInfo.Timeout = new TimeSpan(0, 0, 10);
            client = new SshClient(connectionInfo);
            client.ErrorOccurred += delegate(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
                newdisplay.DisplayData("Client error : " + e.Exception.Message);
            client.HostKeyReceived += delegate(object sender, Renci.SshNet.Common.HostKeyEventArgs arg)
                newdisplay.DisplayData("Conected to : " + tbSSHHost.Text + ":" + tbSSHPort.Text + ". " + connectionInfo.ServerVersion);
                newdisplay.DisplayData("Key Exchange : " + connectionInfo.CurrentKeyExchangeAlgorithm + ". ");
            listenport.Exception += delegate(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
                newdisplay.DisplayData("Listenport error : " + e.Exception.Message);
            listenport.RequestReceived += delegate(object sender, Renci.SshNet.Common.PortForwardEventArgs arg)
                newdisplay.DisplayData("Requested conection to " + arg.OriginatorHost + ":" + arg.OriginatorPort);
            client.KeepAliveInterval = new TimeSpan(0, 0, 30);
                if (listenport.IsStarted)
                    newdisplay.DisplayData("Listening on " + listenport.BoundHost + ":" + listenport.BoundPort);
                tsslStatus.Text = "Connected";
                while (connected)
                tsslStatus.Text = "Disconnected";

please help and thanks in advance
Mar 7, 2013 at 9:45 PM

What do you use for web address?

It seems that you using not valid url that cannot be parsed by OS and I am simply forwarding this exception back to you.
For example, see this post

Mar 8, 2013 at 1:03 AM
Edited Mar 8, 2013 at 1:05 AM
Thank you for your reply.

yes I have problem with DNS resolving on my side, after some test when I use IP address it works fine.
I thought when I use dynamic forwarding (SSH -d), DNS resolving occur on SSH server like Putty and tunnelier does.
Does pass the whole request to ssh server or try parse hostname to ip address before send the request to ssh server?

Mar 8, 2013 at 1:59 AM

It tries to resolve DNS name on the client and then provides IP address to the server.
I think its a protocol restriction so dont think it could change.

Mar 8, 2013 at 2:27 AM

I don't know about protocol restriction, but putty and tunnelier can do dynamic portforward even with DNS disabled on local machine, I guess I have to look putty source code.
Thankyou for your attention, is very good libbrary keep up the good job.

Mar 8, 2013 at 7:45 AM
Edited Mar 8, 2013 at 2:41 PM
Just for information, in SOCK5 we can send domain name as request, I found information from here.

Update : using sshnet-23481
For a quick test, I made change to HandleSocks5 in ForwardedPosrtDynamic.NET.cs:
  • I disable IPv4 & IPv6 (stream.WriteByte(0x01) & stream.WriteByte(0x04))
  • Add domain request (stream.WriteByte(0x03))
  • send domain length
  • send domain name
  • send port
It works for couple website i open, after that it stop responding, not hang/crash but PortForwardEventArgs stop fireing.

Mar 9, 2013 at 3:17 PM

Thanks for pointing it out,

I dont think I should disable IPv4 and IPv6 and only do domain name since it could be problematic for some but I will look into it of course.

So you were using the same code as above and it failed?
Did it throw any error? If so which one.

Mar 11, 2013 at 3:51 PM

I know I shouldn't disable IPv4 and IPv6, It just for a quick test since I don't really know the logic behind SSH.NET.

As I mention before, after I made change to the code It works for couple website then it stop responding without any error thrown.
I'm sorry I cant can help much since my skills are limited.

Mar 11, 2013 at 7:36 PM

No problem,
I actually looked at it but cant figure out a way to allow user to specify what method he wants to use so I guess I will try to address it later as I have more time.

Apr 4, 2013 at 5:54 PM
just for your info, using 24900 build it fix my dynamic portforward not responding problem.

thank you
Apr 4, 2013 at 6:15 PM
Thanks for letting me know.
I think its probably has to do with how I start threads, so I guess it fixed another problem.