2012-01-11 15 views

答えて

5
long currentTime = System.currentTimeMillis(); 
boolean isPinged = InetAddress.getByName(servername).isReachable(2000); // 2 seconds 
currentTime = System.currentTimeMillis() - currentTime; 
if(isPinged) { 
    System.out.println("pinged successfully in "+ currentTime+ "millisecond"); 
} else { 
    System.out.println("PIng failed."); 
} 

しかし、これが唯一のWindowsシステムでのICMP pingを使用するを確認しました。・テンゴエステcodigoパラHACERピング国連EQUIPOのremoto、ペロのLO QU​​Eのキエロのobtener息子ロスのMS(milisegundos)

0
long start = System.currentTimeMillis(); 
long ping; 




String[] command = { "cmd.exe", "/C", "ping 192.168.1.101" }; 
commandProcess = Runtime.getRuntime().exec(command); 
BufferedReader buffy = new BufferedReader(new InputStreamReader(commandProcess.getInputStream())); 
String readline; 
while((readline = buffy.readLine())!=null){ 
System.out.println(readline); 
if(readline.contains("reply")){ 
long ping = System.currentTimeMillis(); 
System.out.println("Pinged in:"+ ping); 
} 
} 
long end = System.currentTimeMillis(); 
String done = "Completed in times:" +start + ping +end; 
0

。 文字列ip = "127.0.0.1"; 文字列pingResult = "";

String pingCmd = "ping " + ip; 
    try { 
     Runtime r = Runtime.getRuntime(); 
     Process p = r.exec(pingCmd); 
     BufferedReader in = new BufferedReader(new 
     InputStreamReader(p.getInputStream())); 
     String inputLine; 
     while ((inputLine = in.readLine()) != null) { 
      System.out.println(inputLine); 
      pingResult += inputLine; 


     } 
     in.close(); 

    } catch (IOException e) { 
     System.out.println(e); 
    } 
} 

public static void main(String[] args) { 

    String ip = "google.com"; 
    runSystemCommand("ping " + ip); 
+0

回答を英語で投稿してください。 –

関連する問題