Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.");
- }
- 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;
- 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);
Add Comment
Please, Sign In to add comment