2

JFrameウィンドウを使用してIPアドレス設定を表示および更新できるプログラムを作成しようとしています。これを純粋にWindowsで実行することを検討しているので、netsh windowsコマンドを使用して詳細を取得/設定できるようにしようとしています。

Windowsコマンド: netsh interface ip show config name="Local Area Connection" | Find "IP" 私が望むものを正確に返しますが、私が書いたコードはパイプを越えて機能しません。「ローカルエリア接続」部分まで書いた場合にのみ機能します。

パイプ機能を使用して具体的に IP アドレスだけを返す方法はありますか? 行を文字列配列、つまり String[] cmd = netsh として渡すことができると読みました........

package ipchanger;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class test {

    private String CMD;

public void executecommand(String CMD) {
        this.CMD = CMD;

        try {
            // Run whatever string we pass in as the command
            Process process = Runtime.getRuntime().exec(CMD);

            // Get input streams
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
            BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));

            // Read command standard output
            String s;
            System.out.println("Standard output: ");
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);

            }

            // Read command errors
            System.out.println("Standard error: ");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
}


public test() {
    String FINDIP = "netsh interface ip show config name=\"Local Area Connection\" | Find \"IP\"";
    //System.out.println(FINDIP);
    executecommand(FINDIP);

}


public static void main(String[] args) {
    new test();
}
}

あなたたちが助けてくれるかもしれないと思った。

4

1 に答える 1