Java 獲取MAC地址2
class getMac
{
public String getMacByIPConfig()
{
String str = "";
String macAddress = "";
try
{
Process pp = Runtime.getRuntime().exec("ipconfig /all ");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
while((str = input.readLine())!=null)
{
if(str.indexOf("Physical Address")!=-1)
{
System.out.println(str);
macAddress = macAddress + ";" + str.substring(str.indexOf(":")+2,str.length());
}
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
return macAddress;
}
}
{
public String getMacByIPConfig()
{
String str = "";
String macAddress = "";
try
{
Process pp = Runtime.getRuntime().exec("ipconfig /all ");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
while((str = input.readLine())!=null)
{
if(str.indexOf("Physical Address")!=-1)
{
System.out.println(str);
macAddress = macAddress + ";" + str.substring(str.indexOf(":")+2,str.length());
}
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
return macAddress;
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.