Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to tell whether a computer is on&running?

 
Michael Herrmann
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to write a program that plays a sound when a computer, specified by it's ip address, comes online/is turned on. It would be great if I wouldn't have to write a client for the observed computer. I just want to know if there is someone at the end of the line at 123.34.12.345(just an example and a fake ip address of course). I could use functionality similar to the MS-Dos ping command, but my friend Google already told me that Java doesn't support such a low-level protocol as used for the ping requests.
Do you know any solution where the observed computer doesn't have to have something in it's autostart that listens on a port just for such higher-level ping requests?
Thanks in advance
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though Java doesn't support ICMP (ping), you can always call "ping" with java.lang.Runtime#exec()
 
Michael Herrmann
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, that's what I needed. As you can see, I'm quite new to Java. It's a pity that my App loses its platform independence this way, but I don't think there's an option.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. What about trying to connect to a port of the host?
If the result is "java.net.ConnectException: Connection refused: no further information" that means the computer is reachable though there is no process listening at that port.
You might use the connect method that is able to throw a SocketTimeoutException.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic