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