使用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