Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to tell whether a computer is on&running?

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic