I am trying to develop an open-source network monitoring application The application scan the network to find all connected devices. It shows all IPs in the given range but the connected devices will appear with checked box (JCheckBox). I list the connected devices in a JTable with information about each device such as name or IP address using address.getHostName() and address.getHostAddress() -Methods in the class InetAddress- Now I am trying to get the physical address (MAC). I tried this code but the application shows the local device only; the devices (connected or disconnected) in the given IPs range did not appear.
byte[] mac = NetworkInterface.getByInetAddress(address).getHardwareAddress();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
String MAC = sb.toString();