zoukankan      html  css  js  c++  java
  • 使用java 执行ping命令

     

    借助 Runtime.getRuntime().exec() 可以运行一个windows的exe程序
    如图,使用java运行 ping 192.168.2.106,返回这样的字符串
    使用java 执行ping命令
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    package socket;
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
     
    public class TestSocket {
     
        public static void main(String[] args) throws IOException {
     
            Process p = Runtime.getRuntime().exec("ping " "192.168.2.106");
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            StringBuilder sb = new StringBuilder();
            while ((line = br.readLine()) != null) {
                if (line.length() != 0)
                    sb.append(line + " ");
            }
            System.out.println("本次指令返回的消息是:");
            System.out.println(sb.toString());
        }
     
    }
  • 相关阅读:
    POJ 1789
    南华大学 复读机(并查集)
    C
    F
    POJ 1988 Cube Stacking
    并查集(一)
    把采集到的数据发送到一个Google Docs或者Google Form上 这个网站提供了参考和例子
    几种空气颗粒物和空气质量传感器
    整流桥
    STM32 中的CEC
  • 原文地址:https://www.cnblogs.com/chinaifae/p/10194470.html
Copyright © 2011-2022 走看看