I'm using SSH.Net in C# and during connection behind a SOCKS5 proxy, I get the following exception:
System.Net.Sockets.SocketException (0x80004005): No such host is known
at System.Net.Dns.GetAddrInfo(String name)
at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
at Renci.SshNet.Session.ConnectSocks5()
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
Connection from the same machine behind the same proxy to the same server is working seamlessly with WinScp with the Do DNS name lookup at proxy end option selected in the site settings:
Is there a way to tell SSH.Net to do the same ?
It does not seem to be possible.
SSH.NET is always doing DNS resolving locally:
var ip = DnsAbstraction.GetHostAddresses(ConnectionInfo.Host)[0];
// Send address type and address
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
SocketWriteByte(0x01);
var address = ip.GetAddressBytes();
SocketAbstraction.Send(_socket, address);
}
else if (ip.AddressFamily == AddressFamily.InterNetworkV6)
{
SocketWriteByte(0x04);
var address = ip.GetAddressBytes();
SocketAbstraction.Send(_socket, address);
}
else
{
throw new ProxyException(string.Format("SOCKS5: IP address '{0}' is not supported.", ip));
}
If you are willing to modify SSH.NET code, you need to replace the code with something like (untested):
// Send address type and address
SocketWriteByte(0x03); // Resolve by proxy
var host = SshData.Ascii.GetBytes(ConnectionInfo.Host);
SocketWriteByte((byte)host.Length);
SocketAbstraction.Send(_socket, host);
What should be an equivalent of this PuTTY/WinSCP code:
assert(type == ADDRTYPE_NAME);
command[3] = 3;
sk_getaddr(p->remote_addr, command+5, 256);
command[4] = strlen(command+5);
len = 7 + command[4]; /* 4 hdr, 1 len, N addr, 2 trailer */
User contributions licensed under CC BY-SA 3.0