我想通過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