除了用ping命令外,还有其他什么方法呢

解决方案 »

  1.   

    java 中有 ping 么?可以建立 Socket 连接网络就是通的,否则就是不通的。
      

  2.   

    用java.net.InetAddress类中的public boolean isReachable(int timeout) throws IOException  这个方法即可。
      

  3.   

    Java可以执行ping的,用套接字也行!
      

  4.   

    可以用Runtime直接执行dos命令,linux系统的话,直接执行shell也可以
      

  5.   

       Runtime  runtime  =  Runtime.getRuntime();  
       Process  process  =null;  
       String  line=null;  
       InputStream  is  =null;  
       InputStreamReader  isr=null;  
       BufferedReader  br  =null;  
       String  ip="www.sna.com.cn";  //待Ping的地址
        try  
       {  
           process  =runtime.exec("ping  "+ip);  
           is  =  process.getInputStream();  
           isr=new  InputStreamReader(is);  
           br  =new  BufferedReader(isr);  
           while(  (line  =  br.readLine())  !=  null  )  
           {  
               System.out.println(line);  
               System.out.flush();  
           }  
           is.close();  
           isr.close();  
           br.close();  
       }  
       catch(IOException  e  )  
       {  
       System.out.println(e);  
           runtime.exit(1);  
       }