The example in this article describes how Java obtains a MAC address. Share to everyone for your reference. as follows:
* * getmacaddress. java * * * description:get Mac addreess * * @author hadeslee * * Created on 2007-9-27, 9:11:15 * * to C hange This template, choose Tools |
Templates * and open the template in the editor.
* * Package test2;
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
/** * */public class Getmacaddress {public static string getmacaddress () {String address = "";
String OS = System.getproperty ("Os.name");
SYSTEM.OUT.PRINTLN (OS);
if (OS!= null && os.startswith ("Windows")) {try {processbuilder PB = new Processbuilder ("ipconfig", "/all");
Process p = Pb.start ();
BufferedReader br = new BufferedReader (New InputStreamReader (P.getinputstream ()));
String Line;
while (line = Br.readline ())!= null) {if (Line.indexof ("Physical Address")!=-1) {int index = Line.indexof (":");
Address = line.substring (index+1);
Break
} br.close ();
return Address.trim ();
catch (IOException e) {}} return to address; } public static void Main (string[] args) {System.out.println ("" + test.getmacaddress ());
}
}
I hope this article will help you with your Java programming.