readmac.java
来自「用JAVA得到本机MAC地址 参考」· Java 代码 · 共 56 行
JAVA
56 行
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( "本机的MAC地址是:" + ReadMAC.checkPhysicalAddress() );
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?