0

How can I ping between two server from the client application running in my system in java. I'm able to ping the server given as input but its doing the ping from my system where the client application is running instead of doing ping from other server to that server. Both Servers are UNIX.

public static String runSystemCommand(String command) {
        String s = "", v = "";
        try {
            Process p = Runtime.getRuntime().exec(command);
            BufferedReader inputStream = new BufferedReader(new InputStreamReader(p.getInputStream()));
            // reading output stream of the command
            while ((s = inputStream.readLine()) != null) {
                Trace.out(1, s);
                v+=s+"\n";
            }
            return v;
        } catch (Exception e) {
            Trace.out(1, "Error"+e);
        }
        return v;
    }

command = ping ipaddress passed as argument to the function.

Jexxer
  • 13
  • 4
  • Just a proposal: https://stackoverflow.com/questions/28968846/can-you-run-a-true-ping-in-java – Dominique Oct 11 '21 at 08:55
  • https://stackoverflow.com/questions/7685439/how-to-test-if-a-remote-system-is-reachable is a ping, with fallback AFAIK. Otherwise use ProcessBuilder which wraps common pitfalls of Prpcess. – Joop Eggen Oct 11 '21 at 08:59
  • i need the ping output when doing ping from one server to another while running the application locally. – Jexxer Oct 20 '21 at 14:43

0 Answers0