aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Listing all IP adresses on local network (LAN) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Listing all IP adresses on local network (LAN)" Watch "Listing all IP adresses on local network (LAN)" New topic
Author

Listing all IP adresses on local network (LAN)

Jarosław Piotrowski
Greenhorn

Joined: Jul 22, 2009
Posts: 5
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.


Why the hell users are displayed as their first and last name...
Aurelian Tutuianu
Ranch Hand

Joined: May 13, 2004
Posts: 86
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.


http://javasign.blogspot.com/
Jarosław Piotrowski
Greenhorn

Joined: Jul 22, 2009
Posts: 5
I want option "A".
Seems like i must code some native c++ code... pity
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Aurelian Tutuianu
Ranch Hand

Joined: May 13, 2004
Posts: 86
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
Sheriff

Joined: Sep 28, 2004
Posts: 18978
    
  40


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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Listing all IP adresses on local network (LAN)