I am using the following code to get the mac adresses: (in main)
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements())
{
NetworkInterface nif = interfaces.nextElement();
byte[] lBytes = nif.getHardwareAddress();
StringBuffer lStringBuffer = new StringBuffer();
if (lBytes != null)
{
for (byte b : lBytes)
{
lStringBuffer.append(String.format("%1$02X ", new Byte(b)));
}
}
System.out.println(lStringBuffer);
}
I have included the following headers:
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.*;
If I run the code, I get the output very long (mostly blank)
and I also get a list of 6 addresses in between
I checked my Ethernet's mac address through ip config
, and it is in the list;
I want to know that which one of them is Ethernet's mac even if I run it on different PCs and I also wanted to know, how to check if they have spoofed the mac address or not...
By Spoofed I mean that if someone after installing windows, changes the mac address in registry or by a software. I read it in one of the posts on some other question in stack overflow, one person commented that the code he wrote would work even if someone had spoofed the mac and therefore the code isn't good. So I suppose that it can be done in java. I would have asked there but I couldn't. I meant that if the PC or laptop doesn't have a wireless, it should take the Ethernet mac address.