NetworkInterface.getNetworkInterfaces() not listing all interfaces

后端 未结 3 1473
野的像风
野的像风 2020-12-03 05:29

I have three interfaces (eth0,Loopback,wlan0) on my machine and i want to get use Java-API to get the mac address.

  • I use this code.

    <         
    
    
            
3条回答
  •  借酒劲吻你
    2020-12-03 05:44

    When calling getNetworkInterfaces Java will return

    all the interfaces on this machine. Returns null if no network interfaces could be found on this machine.

    You are not the only one with this issue. Apparently, on linux Java will return only the interfaces that have an IP Address allocated (i.e. configured adapters).

    But from your application point of view (unless you are building a network configuration application) having an interface without an IP address is like not having it at all. You will have to either poll for interfaces or get them every time you access, say, "Network Preferences" in your application.

提交回复
热议问题