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ã¡ã½ããã使ãã