java.net.NetworkInterfaceを使う。
public static void main(String[] args) throws SocketException{ Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); while(nics.hasMoreElements()){ NetworkInterface nic = nics.nextElement(); String s = ""; byte[] hardwareAddress = nic.getHardwareAddress(); if(hardwareAddress != null){ for(byte b : hardwareAddress){ s += String.format("%02X ", b); } } System.out.printf("%s:%s - %s%n", nic.getName(), nic.getDisplayName(), s); } }
実行するとこんな感じになる。
eth0:eth0 - 08 00 27 4F 4B 60 lo:lo -
Windowsだともっとにぎやかな感じになると思う。
IPAddressからの取得は、NetworkInterface.getByInetAddressメソッドを使う。