In a certain sense, the MAC address of a network interface that is turned off does nor exist. Consider that the MAC address may be supplied to the interface as a command line parameter when the device is initialized. At any rate, this one of the reasons why Java would have difficulty reporting a MAC address on an inactive network interface.
In practice, you may be able to use Runtime.exec(...)
or similar to run the ifconfig
command, and then parse the output to extract the MAC address. However, I don't know if this will always work.
I don't think what you are trying to do makes much sense (for the reason above), but if you are going to try this, you first need to confirm that running ifconfig
tells you the MAC address for a WiFi network interface that is not connected and/or not powered on. The manual page is here. Once you've confirmed that, read the javadocs for Runtime.exec(...)
and ProcessBuilder
. If you need a more basic tutorial, try this one: http://alvinalexander.com/java/java-exec-processbuilder-process-1
I want to know that which one of them is ethernet's mac even if i run it on different PCs
You can't reliably distinguish an ethernet from a WiFi network based on the MAC address.
I Also wanted to know that how to check if they have spoofed the mac adress or not
By spoofed, I assume that you want to know if the MAC address of the NIC has been changed from its (hardware) default. You cannot tell that from Java. Indeed, I doubt you can even tell that natively.
Frankly, it is doubtful that you are going to get anywhere if you try to do this in (pure) Java. The standard Java APIs simply don't support this kind of thing.