• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting all the Host details

 
lala vishwanath
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I want to write a Java application which will return all the hosts in the network.In the InetAddress class there is a method by name getByName() which needs name of host.But I want to get it
automatically.I want to get all active hosts in the network.
Please give your replies .
Thanks in advance
Lala
 
Ryan Langley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Using the way you want to do it, all you have to do is take a network (i.e. #.#.#.0 where number is between 1 and 255) as an argument, and cycle through all the possible addresses for that network (i.e. #.#.#.1, #.#.#.2, ..., #.#.#.255) and calling the getByName method on those addresses. If it succeeds, you have a valid network address. If it fails it will throw an unknown host exception. All you have to do with the exception is catch it but don't do anything so that the loop will continue. I wrote a quick program that does this, and it takes quite a long time to cycle through all the addresses. It would be interesting to see how the InetAddress class works with that method to find a way to speed it up. Hope this helps!
Cheers,
RL
 
lala vishwanath
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a very good idea Ryan.Thanks for your suggestion.
Is there anyway to detect all the hosts in my domain.
Do I need to write a native method to get all hosts from the server .Is there any provision to make windows api calls.
Please pour ideas.
Thanx
Lala

Originally posted by Ryan Langley:
Hello,
Using the way you want to do it, all you have to do is take a network (i.e. #.#.#.0 where number is between 1 and 255) as an argument, and cycle through all the possible addresses for that network (i.e. #.#.#.1, #.#.#.2, ..., #.#.#.255) and calling the getByName method on those addresses. If it succeeds, you have a valid network address. If it fails it will throw an unknown host exception. All you have to do with the exception is catch it but don't do anything so that the loop will continue. I wrote a quick program that does this, and it takes quite a long time to cycle through all the addresses. It would be interesting to see how the InetAddress class works with that method to find a way to speed it up. Hope this helps!
Cheers,
RL

 
Ryan Langley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Once you create an InetAddress object (which can be created with an IP address or host name) you can get the IP address back from it by calling getHostAddress() off of the object. From there you can determine the network address of the domain, and then cycle through the last octet to see if there are any other live hosts on the network.
Cheers,
RL
[This message has been edited by Ryan Langley (edited June 06, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!