Saturday, May 9, 2009

MAC Address onLinux PC from Java Application

package util;
import java.io.*;

public class SystemAttributes {
public String getMacAddress()throws Exception{
String retStr="";
Runtime rt=Runtime.getRuntime();
Process proc=rt.exec("ifconfig");
BufferedReader br=new BufferedReader(new InputStreamReader(proc.getInputStream()));
retStr=br.readLine();
retStr=retStr.substring(retStr.indexOf("HWaddr")+7);
return retStr;
}

public static void main(String args[])throws Exception{
System.out.print(new SystemAttributes().getMacAddress());
}
}

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails