我想通过SSH连接到远程的GNU + Linux机器并执行命令,但使用IPv6地址。使用IPv4地址,它工作得很好。如何使用C#中的SSH.NET库连接IPv6地址
我在Ubuntu 15.04运行和使用的MonoDevelop(单声道4.0)
下面是使用Renci SSH.NET库我的示例代码:
SshClient sshClient = new SshClient (ipV6Address, user, pass);
sshClient.Connect();
SshCommand sshCmd = sshClient.RunCommand (command);
sshClient.Disconnect();
我还试图用Tamirs SshSharp和终端控制。
将[ ]
添加到IPv6地址也不起作用。
我得到以下异常:
System.Net.Sockets.SocketException: Invalid arguments
at System.Net.Sockets.Socket+SocketAsyncResult.CheckIfThrowDelayedException() [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.EndConnect (IAsyncResult result) [0x00000] in <filename unknown>:0
at Renci.SshNet.Session.SocketConnect (System.String host, Int32 port) [0x00000] in <filename unknown>:0
at Renci.SshNet.Session.Connect() [0x00000] in <filename unknown>:0
at Renci.SshNet.BaseClient.Connect() [0x00000] in <filename unknown>:0
at main program...
也许有人能提供给我一个代码示例(在C#)或告诉我,明确支持IPv6地址库。图书馆应该是免费的(最好使用Apache许可证)并可用于商业用途。
问候威马
编辑:
来,我ipAddress
缺乏网络接口,我改变了结论后,我ipAddress
到"fe80::xxxx:xxxx:xxxx:xxxx%2"
(是2是正确的,我用ping6测试)。
这似乎是工作有点“多”,因为异常改为:
System.ArgumentException: host
at Renci.SshNet.ConnectionInfo..ctor (System.String host, Int32 port, System.String username, ProxyTypes proxyType, System.String proxyHost, Int32 proxyPort, System.String proxyUsername, System.String proxyPassword, Renci.SshNet.AuthenticationMethod[] authenticationMethods) [0x00000] in <filename unknown>:0
at Renci.SshNet.PasswordConnectionInfo..ctor (System.String host, Int32 port, System.String username, System.Byte[] password, ProxyTypes proxyType, System.String proxyHost, Int32 proxyPort, System.String proxyUsername, System.String proxyPassword) [0x00000] in <filename unknown>:0
at Renci.SshNet.PasswordConnectionInfo..ctor (System.String host, Int32 port, System.String username, System.String password) [0x00000] in <filename unknown>:0
at Renci.SshNet.SshClient..ctor (System.String host, Int32 port, System.String username, System.String password) [0x00000] in <filename unknown>:0
at Renci.SshNet.SshClient..ctor (System.String host, System.String username, System.String password) [0x00000] in <filename unknown>:0
at main program...
解决
使用SSH.NET的预发布包解决我的问题!
感谢@MartinPrikryl等;)
当您尝试使用IPv6地址时会出现什么错误?原谅我的玩世不恭,但你确定你的网络支持ipv6吗? – pcwizz
您是否尝试首先使用GUI SSH客户端连接到使用IPv6的服务器?像来自PuTTY? –
是的,我的网络支持IPv6。 通过ssh从shell进行连接正在运行。 Sry我忘了添加错误信息^^,但我现在添加了它。 – Wima