I had a problem getting the MAC address of the machine, which was resolved in this issue using the following code:
Process p = Runtime.getRuntime().exec("getmac /fo csv /nh"); java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream())); String line; line = in.readLine(); String[] result = line.split(","); System.out.println(result[0].replace('"', ' ').trim());
However, I would like to know why this code does not work. Each time it reads the MAC address, it returns a different value. At first I thought it was because getHash, perhaps using a timestamp that I don't know ... But even deleting it, the result changes.
the code
public static byte[] getMacAddress() { try { Enumeration<NetworkInterface> nwInterface = NetworkInterface.getNetworkInterfaces(); while (nwInterface.hasMoreElements()) { NetworkInterface nis = nwInterface.nextElement(); if (nis != null) { byte[] mac = nis.getHardwareAddress(); if (mac != null) { return mac;
Example output (I print directly from an array of bytes, but it is enough to see that I think different)
[ B@91cee [ B@95c083 [ B@99681b [ B@a61164 [ B@af8358 [ B@b61fd1 [ B@bb7465 [ B@bfc8e0 [ B@c2ff5 [ B@c8f6f8 [ B@d251a3 [ B@d6c16c [ B@e2dae9 [ B@ef5502 [ B@f7f540 [ B@f99ff5 [ B@fec107
Thanks in advance
Pedro dusso
source share