943,878 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 3162
  • Java RSS
Dec 5th, 2008
0

java ping

Expand Post »
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.
Similar Threads
Reputation Points: 7
Solved Threads: 0
Junior Poster
mrjoli021 is offline Offline
170 posts
since Mar 2007
Dec 6th, 2008
0

Re: java ping

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
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Dec 6th, 2008
0

Re: java ping

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


why am i getting this error?
Reputation Points: 7
Solved Threads: 0
Junior Poster
mrjoli021 is offline Offline
170 posts
since Mar 2007
Dec 6th, 2008
0

Re: java ping

Hello, mrjoli021
I hope the Sun description of Runtime class help you:
http://java.sun.com/j2se/1.4.2/docs/...g/Runtime.html
Last edited by Antenka; Dec 6th, 2008 at 3:45 pm.
Reputation Points: 293
Solved Threads: 82
Posting Whiz
Antenka is offline Offline
361 posts
since Nov 2008
Dec 6th, 2008
0

Re: java ping

You need to use the static getRuntime() method in order to instantiate the Runtime object.
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Dec 6th, 2008
0

Re: java ping

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:

java Syntax (Toggle Plain Text)
  1. public class myClass {
  2.  
  3. private static myClass instance = null;
  4.  
  5. private myClass()
  6. {
  7. // do something when creating the instance
  8. }
  9.  
  10. public static myClass getInstance()
  11. {
  12. if( instance == null )
  13. {
  14. instance = new myClass();
  15. }
  16. return instance;
  17. }
  18. }

The Runtime class does something similar in order to limit the number of instances of Runtime objects to one.
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: help with watch program
Next Thread in Java Forum Timeline: Number checking & User Exceptions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC