ㄓㄤㄑㄧㄤ

java执行ping命令

public static void get() throws IOException{
         String address="10.132.118.110";  
         
            Process process = Runtime.getRuntime().exec("ping "+address);  
            InputStreamReader r = new InputStreamReader(process.getInputStream());  
            LineNumberReader returnData = new LineNumberReader(r);  
     
            String returnMsg="";  
            String line = "";  
            while ((line = returnData.readLine()) != null) {  
                System.out.println(line);  
                returnMsg += line;  
            }  
              
            if(returnMsg.indexOf("100% loss")!=-1){  
                System.out.println("与 " +address +" 连接不畅通.");  
            }  
            else{  
                System.out.println("与 " +address +" 连接畅通.");  
            }  
    }

 

posted @ 2014-11-05 18:25  ㄓㄤㄑㄧㄤ  阅读(1039)  评论(0编辑  收藏  举报
哈哈,页脚部分。