0

In a .properties file I store the local network interface (i.e. MAC address) which I want to be used by my Java application. Then I get that information as a property.

Now I want to get the local IP address currently associated to this MAC address. How could I do that with Java?

Note that I can't use Reverse ARP on a gateway. I don't have any gateway, I work locally only.

Thanks.

3
  • try this Inet4Address.getLocalHost().getHostAddress() Commented Jun 12, 2013 at 8:46
  • Why? Why not just store the IP address? Commented Jun 12, 2013 at 8:58
  • @EJP Because my users change regularly the IP address and I don't want to force them to update it in my app. But thank you. Commented Jun 22, 2013 at 14:37

1 Answer 1

1

You can use NetworkInterface for this (http://docs.oracle.com/javase/6/docs/api/java/net/NetworkInterface.html):

 Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface i = interfaces.nextElement(); if ( i.getHardwareAddress().... ) { } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.