Reputation: 23226
I have a simple security routine that uses an MD5 hash of a concatenation of an IP address and a shared secret from client to server. (The client provides this hash to the server, and the server makes its own hash based on the client's IP and checks for equality.)
The client end may have multiple network interfaces; in development for example we have a public IP address, localhost, and a VPN network address, not to mention IPv6 addresses.
When making requests from the client to the host the client needs to concatenate the IP address of the requesting interface to the shared secret. I'm hung up on the requesting interface part. Other than making this a configuration item is there anyway to determine through the JDK which network interface will be used for resolving and transmitting to a particular host? (I already have the host name as a configuration item so that's not an issue.)
Upvotes: 1
Views: 223
Reputation: 10288
This is fundamentally a network question, not a Java question. And there is no direct way to know your own public IP address even if you only have one interface, let alone several. You could scrape your address off a site like whatismyip.com, but there is no guarantee that the route chosen by your OS to reach that site will always or ever go through the same interface as the route to the server that needs the hashed address.
Upvotes: 3