import java.io.FileWriter;
import java.net.InetAddress;
import java.net.NetworkInterface;
/**
*
* @author andres2288
*http://javayotros.blogspot.com/2015/01/conseguir-mac-en-java.html
*/
public class mac {
public String conseguirMAC(){
StringBuilder sb = new StringBuilder();
NetworkInterface a; String linea;
try {
a = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
byte[] mac = a.getHardwareAddress();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
FileWriter fwriter = new FileWriter("mac.dat");
fwriter.write("MAC: " + sb.toString());
fwriter.close();
// lmac.setText("SE ha registrado la MAC exitosamente.");
} catch (Exception e) {
e.printStackTrace();
}
return ""+sb.toString();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
mac p = new mac();
System.out.println(""+p.conseguirMAC());
}
}
eso es todo espero haberles ayudado
0 Comments