I am trying to write a program that will monitor my routers and servers and notify me when they go down. I am looking for a way to ping the host and read the reply. The InetAddress.isReachable method is the only thing i could find but it uses the echo port which windows has it off by default. i am looking for something generic that i can use on diffrent platforms. Windows, Linux, Cisco OS.

Recommended Answers

All 5 Replies

Take a look at the Runtime class. You can use its exec method to run a ping and the resulting Process has methods to allow you to obtain the I/O/E streams. This allows you to interpret the results of your ping, but note that there are differences in the ping implementation in Windows and Linux (not sure about Cisco OS sorry).

Hope this gives you some direction,
darkagn

Runtime() has private access in java.lang.Runtime
Runtime r = new Runtime();


why am i getting this error?

You need to use the static getRuntime() method in order to instantiate the Runtime object.

As an aside, if you want to limit people to only use one instance of your class in an application, you can do something like this:

public class myClass {

  private static myClass instance = null;

  private myClass()
  {
    // do something when creating the instance
  }

  public static myClass getInstance()
  {
    if( instance == null )
    {
      instance = new myClass();
    }
    return instance;
  }
}

The Runtime class does something similar in order to limit the number of instances of Runtime objects to one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.