Package Cn.net. comsys. License. app;
/**
* @ Author Jif
* @ Version Creation Time: 09:14:52
* E-mail: liaojifeng@163.com
* Class description:
*
*
*
*/
Import Java. Io. bufferedreader;
Import Java. Io. ioexception;
Import Java. Io. inputstreamreader;
Import Java. util. properties;
Import Java. util. Logging. level;
Import Java. util. Logging. Logger;
Public Class Osmactool {
Public StaticString getmacaddress (){
String address = "";
String OS = system. getproperty ("OS. Name ");
// System. Out. println (OS );
If (OS! = Null ){
If (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 ){
}
} Else If (OS. startswith ("Linux ")){
Try {
Processbuilder Pb = New Processbuilder ("ifconfig ");
PROCESS p = Pb. Start ();
Bufferedreader BR = New Bufferedreader ( New Inputstreamreader (P. getinputstream ()));
String line;
While (Line = Br. Readline ())! =Null ){
Int Index = line. indexof ("hardware address ");
If (Index! =-1 ){
Address = line. substring (index + 4 );
Break ;
}
}
BR. Close ();
Return Address. Trim ();
} Catch (Ioexception ex ){
Logger. getlogger (osmactool. Class . Getname (). Log (level. Severe, Null , Ex );
}
}
}
Return Address;
}
Public Static VoidMain (string [] ARGs ){
System. Out. println ("" + osmactool. getmacaddress ());
}
}