使用Java測試網絡連通性的幾種方法


使用Java測試網絡連通性的幾種方法

調用dos命令得到返回值

String command="ipconfig -all";
        String s="IPv4";
        String line = null;
        StringBuilder sb = new StringBuilder();
        Runtime runtime = Runtime.getRuntime();
        try {
        Process process = runtime.exec(command);
        BufferedReader    bufferedReader = new BufferedReader
                (new InputStreamReader(process.getInputStream()));
        
        
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line + "\n");
                if (line.contains(s)) {
                    System.out.println(line);
                }
            }
        } catch (IOException e) {
            // TODO 自動生成的 catch 塊
            e.printStackTrace();
        }
        //System.out.println(sb.toString());


Java判斷和檢查網絡

java中判斷網絡是否連通

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM