I have written a code that saves "arp -a" data into notepad file. The problem is that this output comes like a single string but I would like to display the arp cache table into rows and columns format (like most network monitoring tools do). I need a way to get the arp table in rows and columns so I can use that data structure to perform further tasks. Below is some code I came through:
public String getMacAddress() throws SocketException, UnknownHostException{
NetworkInterface netint = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
StringBuilder sb = new StringBuilder();
byte [] mac=netint.getHardwareAddress();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i],""));
}
return sb.toString();
}
public StringBuilder IPtoHex(String IP){
String [] address = IP.replace(".", ":").split(":");
StringBuilder str = new StringBuilder();
for(String s : address){
s=Integer.toHexString(Integer.parseInt(s));
s=(s.length()<2)?"0"+s:s;
str.append(s);
}
...
}
I want the output to look like something like this: