Java: How do I get the IP of the local interface that can reach a remote IP?
Posted
by Per Fagrell
on Stack Overflow
See other posts from Stack Overflow
or by Per Fagrell
Published on 2010-06-08T06:53:30Z
Indexed on
2010/06/08
7:02 UTC
Read the original article
Hit count: 175
I have a Java application that registers a server component in a service provider, and then sends the service name to a client. The client uses the service name to get an address out of the service provider to the server. However, the server has several interfaces only 1 of which the client get get at, so the service must be registered with the right IP. We discovered the client through a broadcast, so I have the client IP and an Enumeration of the computers network interfaces. How do I match the IP to an interface, not knowing what the netmask of the client IP is?
Spontaneously I imagine turning all the addresses to ints and chomping the local ips with their netmask and looking for a 'best match', but I wonder if there is a better way?
(this is an enterprise(tm) solution, so cutting out the service provider isn't an option, at least not w/o a political campaign first ;) )
© Stack Overflow or respective owner