编写类似ping命令的  大概个点想法 就行   我的意思是想获得 连接 的 响应毫秒  给个例子好吗 我没找到 那个类的方法!!!

解决方案 »

  1.   

    以下ping 192.168.0.1 可以用args 来传参数,以达到动态ping某个IPimport java.io.*;public class Test
    {
    public static void main(String[] args) throws Exception
    {

    Process pro = Runtime.getRuntime().exec("ping 192.168.0.1");

    pro.waitFor();

    BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));

    String str = br.readLine();
    while(str != null)
    {
    System.out.println(str);
    str = br.readLine();
    }
    }
    }运行如下:
    F:\>java TestPinging 192.168.0.1 with 32 bytes of data:
    Reply from 192.168.0.1: bytes=32 time<1ms TTL=128
    Reply from 192.168.0.1: bytes=32 time<1ms TTL=128
    Reply from 192.168.0.1: bytes=32 time<1ms TTL=128
    Reply from 192.168.0.1: bytes=32 time<1ms TTL=128
    Ping statistics for 192.168.0.1:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum = 0ms, Average = 0ms
      

  2.   

    解析获得到的串,比如获取Average后的值.