java - 使用 JSch 连接到 Cisco WLC 时出现 NullPointerException

标签 java ssh jsch cisco

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

Exception: com.jcraft.jsch.JSchException: java.lang.NullPointerException

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 的隐藏位置。 我修好了它,惊喜,惊喜,它有效!非常非常感谢马丁的支持!

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: curve25519-sha256@libssh.org,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: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
INFO: kex: server: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
INFO: kex: server: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
INFO: kex: server: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
INFO: kex: server: none,zlib@openssh.com,zlib
INFO: kex: server: none,zlib@openssh.com,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

关于java - 使用 JSch 连接到 Cisco WLC 时出现 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47430004/

相关文章:

docker - 在远程 docker swarm 集群上运行手动 GitLab CI 作业时遇到问题

java - 存储 Java 对象以供在使用 REST 的 Web 应用程序中进一步使用

java - PaintComponent 未由构造函数或创建对象时调用

node.js - 如何在 Jenkins 管道中使用 SSH?

ssh - 如何通过 ssh 进入 Google Cloud Shell?

Java - JSch - 获取退出状态 123. 这是什么意思?

java - 使用 JSCH、apache mina sshd 或 sshj 的 Open SSH 的 SSH Exec channel

java - 在构造函数中将对象添加到静态 ArrayList 是不好的做法吗?

java - JToolBar 项目顺序

java - Tomcat 全局连接池获取错误