Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listing all IP adresses on local network (LAN)

 
Jarosław Piotrowski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First... I've search'd for this on google and didn't find any good answer.
Then I've searched for it on this forum... but, i only found only a thread-question about it with only one answer
"Please do not cross-post the same question in multiple forums" etc. and topic is closed.

So, I cannot find it by using search feature on this forum, and the guy in that topic suggests that this question was made earlier.
If teh answer for my question exists on this forum, then it needs better tags to find it - I just couldn't. Typing anything related to this I got no results, or got too many not related to my question.
That is the reason why i am re-posting this question - I couldn't find and it is hard (if it is even possible) to find an anserwer to my question by using search..

How I can get/list all IP addresses of machines I am connection to via LAN - Can I even do that with Java? or if not, how can I do it with native C++ on linux,mac and windows (i am not a c++ programmer, so i would need a complete examples)
I'd rather prefer a non-native solution.
 
Aurelian Tutuianu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jarek notgonnashare wrote:I can get/list all IP addresses of machines I am connection to via LAN
I am afraid that I don't understood well your question.

A. Do you want to know the IP addresses of the machines from the same LAN?
B. Do you want to know all the IP addresses of a system to which you have a remote connection?

For both, there's no standard API in JDK.
The only thing you have in JDK is NetworkInterface.getNetworkInterfaces() which give you an array of network interfaces (cards). Every one can list its own IP addresses.
The other Java native ways I don't know.
 
Jarosław Piotrowski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want option "A".
Seems like i must code some native c++ code... pity
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not necessarily. You can use InetAddress.getLocalHost(), and NetworkInterface.getNetworkInterfaces() (as Aurelian Tutuianu suggested). With those you can get the IP address(es) of your machine. Using the former:
 
Aurelian Tutuianu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was thinking on the same solution as Rob Prime stated before. But there is a problem with that solution - pinging all the possible hosts based on IP.
I wonder that is possible the have in the same LAN different IP classes, I think yes but I am not sure. If it's true than the ping solution must be extended somehow.
 
Henry Wong
author
Marshal
Pie
Posts: 21208
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Also, this solution assumes a netmask of 255.255.255.0. For anything else, you will be trying to ping IPs which are not part of the LAN, or not ping IPs which are part of the LAN.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic