java ping

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2007
Posts: 159
Reputation: mrjoli021 is an unknown quantity at this point 
Solved Threads: 0
mrjoli021 mrjoli021 is offline Offline
Junior Poster

java ping

 
0
  #1
Dec 5th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 801
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: java ping

 
0
  #2
Dec 6th, 2008
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
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 159
Reputation: mrjoli021 is an unknown quantity at this point 
Solved Threads: 0
mrjoli021 mrjoli021 is offline Offline
Junior Poster

Re: java ping

 
0
  #3
Dec 6th, 2008
Runtime() has private access in java.lang.Runtime
Runtime r = new Runtime();


why am i getting this error?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 254
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: java ping

 
0
  #4
Dec 6th, 2008
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.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 801
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: java ping

 
0
  #5
Dec 6th, 2008
You need to use the static getRuntime() method in order to instantiate the Runtime object.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 801
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: java ping

 
0
  #6
Dec 6th, 2008
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:

  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.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC