akshay
akshay

Reputation: 5285

how can i check if remote machine is up or not?

1)How can i check if a remote machine is up (up meaning its on and running).
2)Also how can i get the time for which the machine is up since the time it started last time?

I will hava a java program running on machine A which will check if machine C and D is up and the tie for which the machine is up. Both machine are in same LAN.
Program should be a able to check if any windows machine is up.How can i check the same for linux if possibe?I am more interested in windows as machine C and D

Upvotes: 1

Views: 3183

Answers (2)

sealz
sealz

Reputation: 5408

If you would like to ping from within JAVA you can do something this.

import java.net.Socket;

//7 specifies Socked
Socket t = new Socket("111.111.1.11", 7);

EDIT: I would assume you can simply assign the socket as in the command prompt.

example = String ip = XXX.XXX.X.XX:XXXX

Or to ping a specific IP on the network you can use this.

public static void main(String[] args) {

        // ip = IP/website you want to ping or google!
        String ip = "google.com";
        //Don't forget to leave a space after ping
        String pingcmd = "ping " + ip;
        Runtime r = Runtime.getRuntime();
        Process p;
    try {
        p = r.exec(pingcmd);
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
       String inputLine;
       while ((inputLine = in.readLine()) != null) {

       System.out.println(inputLine);
        }
    }
     catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

Upvotes: 2

Steve Claridge
Steve Claridge

Reputation: 11090

You can ping a machine to see if it is running and reachable across the network.

If you want another machine to return specific information, like uptime, then you need to have some kind of service running on the target machine and then call that to retrieve uptime.

Sockets are something to consider if you need more than Ping. Or, and it's probably overkill, you can run Tomcat on the target machine and then call them over HTTP.

Upvotes: 0

Related Questions