• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pinging IP Addresses...

 
Gale Greaser
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I'm writing an application that needs to know if a given IP address is being used. Therefore I'm looking to find a the best and fastest way to [perhaps] ping an IP address.
I'm looking for something that works like this:
PingManager ping = new PingManager()
boolean pinged = ping("152.265.45.7");
Right now I'm using HttpURLConnection.connect() to "ping". I'm not getting a warm-fuzzy with this method seeing as it takes a long time to return 'false' if the given IP is not being used.
I would like to know the best way to find if an IP is being used.
I was debating whether or not C++ would be a better candidate for this portion of the code.
Any ideas would be much appriciated.
Thanks in advance!
Gale
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not do a real ping in java, because all java supports is TCP and UDP sockets. Ping is ICMP.
But you can try to open a socket to some well-known port on that machine and at least see if the port is there. But you can't rely on any port being always available.
If the machine is running a web server, then port 80 will probably be there. If it runs ftp, then it'll have port 21. Telnet is 23, sendmail 25, echo 7, etc.
If that's good enough for ya, you can just do:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic