现在的位置: 首页 > 综合 > 正文

java实现判断两主机是否相连!

2013年08月01日 ⁄ 综合 ⁄ 共 606字 ⁄ 字号 评论关闭

package com.csdn.test;

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

public class test {
 static BufferedReader bufferedReader;

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

  try {
   Process process = Runtime.getRuntime().exec("ping 192.168.1.104");//判断是否连接的IP;
   bufferedReader = new BufferedReader(new InputStreamReader(process
     .getInputStream()));
   String connectionStr = "";
   while ((connectionStr = bufferedReader.readLine()) != null) {
    System.out.println(connectionStr);
   }
   
   

  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   bufferedReader.close();
  }
 }
}

抱歉!评论已关闭.