?? readmac.java
字號:
import java.io.*;
class ReadMAC
{
public static String physicalAddress = "read MAC error";
public ReadMAC()
{
}
public static String checkPhysicalAddress()
{
try
{
String line;
Process process = Runtime.getRuntime().exec("C:\\WINDOWS\\system32\\ipconfig /all");
//Process process = Runtime.getRuntime().exec("cmd /c ipconfig /all");
//Process process = Runtime.getRuntime().exec("E:\\QQ\\QQ.exe" );
System.out.println("begin to read mac address" );
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
System.out.println( "hehe" );
while( ( line = br.readLine() ) != null )
{
if( line.indexOf( "Physical Address. . . . . . . . . :") != -1 )
{
if ( line.indexOf( ":" ) != -1 )
{
physicalAddress = line.substring( line.indexOf(":") + 2 );
break;
}
}
}
line = br.readLine();
System.out.println( line );
System.out.println( "ok" );
process.waitFor();
}
catch ( Exception e )
{
e.printStackTrace();
}
return physicalAddress;
}
public static void main(String[] args)
{
System.out.println("Hello World!");
System.out.println( "本機(jī)的MAC地址是:" + ReadMAC.checkPhysicalAddress() );
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -