• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Listing all IP adresses on local network (LAN)

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want option "A".
Seems like i must code some native c++ code... pity
 
Marshal
Posts: 22444
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic