多年来,我一直使用JSch连接到Cisco交换机。今天,我尝试以与交换机相同的方式连接到Cisco WLC。没用!



WLC和交换机之间的区别在于,如果您首先尝试在WLC中使用PuTTY登录,则WLC要求输入“登录为:”。在这里,您可以编写fooBar或什么都不做。之后,WLC要求输入用户名和密码!
这是我使用的代码:

java.util.Properties configuration = new java.util.Properties();

configuration.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");
configuration.put("StrictHostKeyChecking", "no");

final JSch jsch = new JSch();
final Session session = jsch.getSession(TELNET_USER, outletWLC.getIp(),22);

session.setPassword(TELNET_PASSWORD);
session.setConfig(configuration);
session.connect();      // Here I get the Exception!
if (!session.isConnected()) {
   throw new RuntimeException("cannot connect session");
}

final ChannelShell channelShell = (ChannelShell) session.openChannel("shell");
final ByteArrayInputStream toSwitchStream =
    new ByteArrayInputStream(commandString.getBytes());

final ByteArrayOutputStream fromSwitchStream = new ByteArrayOutputStream();
final int available = toSwitchStream.available();
channelShell.setInputStream(toSwitchStream);
channelShell.setOutputStream(fromSwitchStream);

channelShell.connect();

周围有人解决了这个问题吗?

com.jcraft.jsch.JSchException: java.lang.NullPointerException
    at com.jcraft.jsch.Session.receive_kexinit(Session.java:544)
    at com.jcraft.jsch.Session.connect(Session.java:291)
    at com.jcraft.jsch.Session.connect(Session.java:154)
    at de.mediamarkt.indira.server.services.MSVorfPasswServiceImpl.readWLC(MSVorfPasswServiceImpl.java:169)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at de.mediamarkt.indira.server.remote.IndiraProxyServlet.service(IndiraProxyServlet.java:93)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1097)
    at de.mediamarkt.indira.server.filter.IndiraMultiPersistenceUnitTransactionFilter.doFilter(IndiraMultiPersistenceUnitTransactionFilter.java:23)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    at org.mortbay.jetty.handler.HandlerList.handle(HandlerList.java:49)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.lang.NullPointerException
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.jcraft.jsch.Session.receive_kexinit(Session.java:540)
    ... 26 more

JSch日志:

INFO: Connecting to 10.3.xxx.xxx port 22
INFO: Connection established
INFO: Remote version string: SSH-2.0-CISCO_WLC
INFO: Local version string: SSH-2.0-JSCH-0.1.44
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: aes256-ctr is not available.
INFO: aes192-ctr is not available.
INFO: aes256-cbc is not available.
INFO: aes192-cbc is not available.
INFO: arcfour256 is not available.
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received
INFO: kex: server->client aes128-ctr hmac-sha1 none
INFO: kex: client->server aes128-ctr hmac-sha1 none
INFO: Disconnecting from 10.3.xxx.xxx port 22

最佳答案

现在,我找到了一个隐藏的地方,在这里我继承的项目加载了错误的JSch版本。
我修好了,惊奇,惊奇,它起作用了!!非常感谢Martin的支持!

INFO: Connecting to 10.3.xxx.xxx port 22
INFO: Connection established
INFO: Remote version string: SSH-2.0-CISCO_WLC
INFO: Local version string: SSH-2.0-JSCH-0.1.54
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: aes256-ctr is not available.
INFO: aes192-ctr is not available.
INFO: aes256-cbc is not available.
INFO: aes192-cbc is not available.
INFO: CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
INFO: CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received
INFO: kex: server: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
INFO: kex: server: ssh-rsa,rsa-sha2-512,rsa-sha2-256
INFO: kex: server: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
INFO: kex: server: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
INFO: kex: server: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
INFO: kex: server: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
INFO: kex: server: none,[email protected],zlib
INFO: kex: server: none,[email protected],zlib
INFO: kex: server:
INFO: kex: server:
INFO: kex: client: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256
INFO: kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
INFO: kex: client: none
INFO: kex: client: none
INFO: kex: client:
INFO: kex: client:
INFO: kex: server->client aes128-ctr hmac-sha1 none
INFO: kex: client->server aes128-ctr hmac-sha1 none
INFO: SSH_MSG_KEXDH_INIT sent
INFO: expecting SSH_MSG_KEXDH_REPLY
INFO: ssh_rsa_verify: signature true
WARN: Permanently added '10.3.xxx.xxx' (RSA) to the list of known hosts.
INFO: SSH_MSG_NEWKEYS sent
INFO: SSH_MSG_NEWKEYS received
INFO: SSH_MSG_SERVICE_REQUEST sent
INFO: SSH_MSG_SERVICE_ACCEPT received

10-04 11:55