How to get localhost network interface in java or scala
java, scala
Solution
`getByInetAddress` has the same broken behavior on my machine, but you can use `getNetworkInterfaces` instead:
import java.net._
import scala.collection.JavaConverters._
NetworkInterface.getNetworkInterfaces.asScala map (_.getHardwareAddress) filter (_ != null)
Problem
I'm trying to get the MAC address for my machine inside a scala application. There are several results when searching, but they all use something like the following, involving `InetAddress.getLocalHost()` followed by `NetworkInterface.getByInetAddress(...)`: Get MAC address on local machine with Java My problem is that the result ends up being null: ``` val localhost = InetAddress.getLocalHost println(s"lh: $localhost") val localNetworkInterface = NetworkInterface.getByInetAddress(localhost) println(s"lni: $localNetworkInterface") >>lh: ubuntu/127.0.1.1 >>lni: null ```