Guest User

Untitled

a guest
Feb 25th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. long currentTime = System.currentTimeMillis();
  2. boolean isPinged = InetAddress.getByName(servername).isReachable(2000); // 2 seconds
  3. currentTime = System.currentTimeMillis() - currentTime;
  4. if(isPinged) {
  5. System.out.println("pinged successfully in "+ currentTime+ "millisecond");
  6. } else {
  7. System.out.println("PIng failed.");
  8. }
  9.  
  10. long start = System.currentTimeMillis();
  11. long ping;
  12.  
  13.  
  14.  
  15.  
  16. String[] command = { "cmd.exe", "/C", "ping 192.168.1.101" };
  17. commandProcess = Runtime.getRuntime().exec(command);
  18. BufferedReader buffy = new BufferedReader(new InputStreamReader(commandProcess.getInputStream()));
  19. String readline;
  20. while((readline = buffy.readLine())!=null){
  21. System.out.println(readline);
  22. if(readline.contains("reply")){
  23. long ping = System.currentTimeMillis();
  24. System.out.println("Pinged in:"+ ping);
  25. }
  26. }
  27. long end = System.currentTimeMillis();
  28. String done = "Completed in times:" +start + ping +end;
  29.  
  30. String pingCmd = "ping " + ip;
  31. try {
  32. Runtime r = Runtime.getRuntime();
  33. Process p = r.exec(pingCmd);
  34. BufferedReader in = new BufferedReader(new
  35. InputStreamReader(p.getInputStream()));
  36. String inputLine;
  37. while ((inputLine = in.readLine()) != null) {
  38. System.out.println(inputLine);
  39. pingResult += inputLine;
  40.  
  41.  
  42. }
  43. in.close();
  44.  
  45. } catch (IOException e) {
  46. System.out.println(e);
  47. }
  48. }
  49.  
  50. public static void main(String[] args) {
  51.  
  52. String ip = "google.com";
  53. runSystemCommand("ping " + ip);
Add Comment
Please, Sign In to add comment