weixin_42497641 2012-02-08 15:16
浏览 257
已采纳

怎么通过ping返回的值获得系统信息;什么系统,及系统的位数

package com;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class TimerExecPing {

/**
 * @param args
 */
public static void ping(final String host) {
    String system = (String) (System.getProperty("os.name")).toLowerCase();
    String command = "";
    if (system.indexOf("xp") != -1 || system.indexOf("win") !=-1) {
        command += "ping win " + host;
        System.out.println(command);
    } else if (system.indexOf("linux") != -1) {
        command += "ping linux" + host;
        System.out.println(command);
    } else {
        command += "ping " + host;
        System.out.println(command);
    }
    TimerTask timerTask = new TimerTask() {
        public void run() {
            Process process;
            try {
                process = Runtime.getRuntime().exec("ping " + host);
                String result = "";
                BufferedReader input = new BufferedReader(
                        new InputStreamReader(process.getInputStream(),
                                "gbk"));
                String line;
                while ((line = input.readLine()) != null) {
                    result += line;
                    // result=line.split(" ");
                    System.out.println(line);

                }
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };
    Timer timer = new Timer();
    timer.schedule(timerTask, new Date());
}
           public static void main(String[] args) {
    TimerExecPing pi=new TimerExecPing();
    pi.ping("200.1.1.60");
}

}
图为通过ping ip的结果,然后我怎么做。能给出代码最好

  • 写回答

3条回答 默认 最新

  • sz_147258 2012-02-09 13:04
    关注

    [code="java"]String line = "这里判断每一行是否包含TTL=64";
    int type = 0;
    if (line.indexOf("TTL") != -1) {
    type = Integer.valueOf(line.substring(line.length() - 2,
    line.length()));
    switch (type) {
    case 64: {
    //这里你自己去看看TTL代表什么吧
    break;
    }
    case 255: {
    break;
    }
    default:
    }
    }[/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制