• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring 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: 23958
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
 
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic