java - 超微 IPMI KVM : remote connection without webbrowser

标签 java jnlp ikvm ipmitool ipmi

我尝试在不使用网络浏览器或 IPMIview 工具的情况下连接 IPMI 远程连接 (KVM)。但到目前为止还没有运气。

我首先想到的是用 javaws 启动“jviewer.jnlp”。如果您按下“远程连接”按钮,IPMI 网站将创建此文件。此解决方案一直有效,直到网络 session 关闭。我尝试用用户名和密码替换加密参数。但是以某种方式嵌入了 session ID。

jviewer.jnpl 文件:

<?xml version="1.0" encoding="UTF-8"?>

<jnlp spec="1.0+" codebase="https://192.168.99.201/Java">
 <information>
    <title>JViewer</title>
    <vendor>American Megatrends, Inc.</vendor>
    <description kind="one-line">JViewer Console Redirection Application</description>
    <description kind="tooltip">JViewer Console Redirection Application</description>
    <description kind="short">
        JViewer enables a user to view the video display of managed server via KVM.  
        It also enables the user to redirect his local keyboard, mouse for managing the server remotely.
    </description>
</information>
<security>
    <all-permissions/>
</security>
<resources>
    <j2se version="1.5+"/>
    <jar href="release/JViewer.jar"/>
</resources>
<resources os="Windows" arch="x86">
    <j2se version="1.5+"/>
    <nativelib href="release/Win32.jar"/>
</resources>    
<resources os="Windows" arch="amd64">
       <j2se version="1.5+"/>
       <nativelib href="release/Win64.jar"/>
</resources>
<resources os="Linux"  arch="x86">
    <j2se version="1.5+"/>
        <nativelib href="release/Linux_x86_32.jar"/>
</resources>
<resources os="Linux"  arch="i386">
    <j2se version="1.5+"/>
        <nativelib href="release/Linux_x86_32.jar"/>
</resources>
<resources os="Linux" arch="x86_64">
    <j2se version="1.5+"/>
        <nativelib href="release/Linux_x86_64.jar"/>
</resources>    
<resources os="Linux" arch="amd64">
    <j2se version="1.5+"/>
        <nativelib href="release/Linux_x86_64.jar"/>
</resources>
<resources os="Mac OS X" arch="i386">
    <j2se version="1.5+"/>
        <nativelib href="release/Mac32.jar"/>
</resources>
<application-desc>
    <argument>192.168.99.201</argument>
    <argument>5901</argument>
    <argument>Hnda9A159AwMjwnF</argument>
    <argument>0</argument>
    <argument>0</argument>
    <argument>5120</argument>
    <argument>5123</argument>
    <argument>511</argument>
    <argument>5900</argument>
    <argument>1</argument>
    <argument>EN</argument>
    <argument>HEWKovXQO2Fp7FEMho6LrM4kzTPFHPyB000</argument>

</application-desc>
</jnlp>

如果 jnlp 被命名为“launch.jnlp”,参数用户名和密码替换将起作用一些 Supermicro IPMI 版本将使用不同的结构。

其次,我尝试连接 IPMIview 工具版本 2.9.32。那工作所以连接没问题。知道我使用 IPMIview 的 jar 尝试连接。用IPMI IP替换host

java -Djava.library.path=. -jar iKVM.jar host ADMIN ADMIN null 5900 2623 2 0

这将打开远程连接,但会出现“连接失败”错误。

java -Djava.library.path=. -jar JViewerX9.jar host ADMIN ADMIN

同样的结果:连接失败 连接失败带有一个警告框。 OK 关闭应用程序

一些 IPMI 信息:

# ipmitool mc info
Device ID                 : 32
Device Revision           : 1
Firmware Revision         : 2.4
IPMI Version              : 2.0
Manufacturer ID           : 47488
Manufacturer Name         : Unknown (0xB980)
Product ID                : 43707 (0xaabb)
Product Name              : Unknown (0xAABB)
Device Available          : yes
Provides Device SDRs      : no
Additional Device Support :
    Sensor Device
    SDR Repository Device
    SEL Device
    FRU Inventory Device
    IPMB Event Receiver
    IPMB Event Generator
    Chassis Device
Aux Firmware Rev Info     : 
    0x01
    0x00
    0x00
    0x00

冷重置“ipmitool mc reset cold”也不起作用。

我希望有人知道这个参数对 jnlp 文件的意义,或者有人有解决这个问题的有效方法

编辑: 我尝试了 Maxim Akristiniy 的答案并提出了以下代码:

package com.thalesgroup.nl.perftools;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.util.List;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.ScriptResult;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.util.Cookie;

public class IpmiRemoteViewer {

    public static void main(String[] args)
            throws FailingHttpStatusCodeException, MalformedURLException,
            IOException {

        String username = "ADMIN";
    String password = "ADMIN";
    String ip = "192.168.99.150";

    final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17);

    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.getCookieManager().setCookiesEnabled(true);

    webClient.getOptions().setUseInsecureSSL(true);
    webClient.getOptions().setJavaScriptEnabled(true);

    webClient.getCookieManager().addCookie(
            new Cookie(ip, "WEBVAR_USERNAME", username));
    webClient.getCookieManager().addCookie(
            new Cookie(ip, "WEBVAR_PASSWORD", password));

    HtmlPage page1 = webClient.getPage("http://" + ip);

    List<HtmlForm> forms = page1.getForms();

    if (!forms.isEmpty()) {

        HtmlForm form = forms.get(0);
        HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue(
                "Login").get(0);

        // username
        HtmlTextInput textField = form.getInputByName("T1");
        textField.setValueAttribute(username);

        // password
        HtmlPasswordInput textField2 = form.getInputByName("T2");
        textField2.setValueAttribute(password);

        HtmlPage page2 = button.click();
        webClient.waitForBackgroundJavaScript(500);

        // Do it again
        form = page2.getForms().get(0);

        // username
        textField = form.getInputByName("T1");
        textField.setValueAttribute(username);

        // password
        textField2 = form.getInputByName("T2");
        textField2.setValueAttribute(password);

        ScriptResult scriptResult = page2.executeJavaScript("DoLogin();");

        // Print the index.html page
        System.out.println(scriptResult.getNewPage().toString());

        // Print the session id
        for (Cookie cookie : webClient.getCookieManager().getCookies()) {
            if (cookie.getName().equals("SessionCookie")) {
                String sessionId = cookie.getValue();
                System.out.println("Session id = " + sessionId);
            }
        }

        // Download the jviewer.jnlp file
        Page page5 = webClient.getPage("http://" + ip
                + "/Java/jviewer.jnlp?EXTRNIP=" + ip + "&JNLPSTR=JViewer");
        WebResponse response = page5.getWebResponse();
        InputStream inputStream = response.getContentAsStream();

        writeToFile("viewer.jnlp", inputStream);
    }

}

protected static void writeToFile(String filename, InputStream inputStream) {
    OutputStream outputStream = null;

    try {

        File file = new File(filename);

        // write the inputStream to a FileOutputStream
            outputStream = new FileOutputStream(file);

            int read = 0;
            byte[] bytes = new byte[1024];

            while ((read = inputStream.read(bytes)) != -1) {
                outputStream.write(bytes, 0, read);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }
    }

}

只有现在它才会在 viewer.jnlp 文件中写入登录页面。仍然没有运气。我设法阅读了登录页面后面的 index.html 页面。但是 session 结束得非常快。

最佳答案

下载 jviewer.jnlp 文件但首先登录。

#!/bin/sh

USER=ADMIN
PASS=ADMIN
HOST=192.168.99.150

COOKIE=`curl --data "WEBVAR_USERNAME=$USER&WEBVAR_PASSWORD=$PASS" http://$HOST/rpc/WEBSES/create.asp 2> /dev/null | grep SESSION_COOKIE | cut -d\' -f 4`
curl --cookie Cookie=SessionCookie=$COOKIE http://$HOST/Java/jviewer.jnlp -o $HOST.jviewer.jnlp

然后用javaws启动jviewer.jnlp文件

关于java - 超微 IPMI KVM : remote connection without webbrowser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26160165/

相关文章:

Java while 循环在满足所有条件之前停止

java - 如何重新创建或刷新 fragment

java - 将 --add-opens 参数传递给 Java webstart

c# - weka .net ikvm -> 为什么加载 csv 文件这么慢?

c# - .net:DLL 的依赖加载与 EXE 的依赖加载不同吗?

java - JSF 中值的逻辑

java - 如何为每个数据中心选择备用机器?

java - 网络启动 : What os and arch does my system return?

Java Web Start 安全警告 JNLP。 JWS 中的错误? 7u51

c# - Java 和 .NET 流通过 IKVM 的互操作性