⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macaddressaccess.java

📁 如何使用java来获取机器的MAC地址
💻 JAVA
字号:
import java.io.*; 
public class MacAddressAccess {
	public MacAddressAccess() { 
	}
	private static String getMyMac() {
		String s = "";
		try {
			String s1 = "ipconfig /all";
			// 相当于在命令行下直接使用ipconfig /all
			Process process = Runtime.getRuntime().exec(s1); 
			BufferedReader bufferedreader = new BufferedReader(new 
                       InputStreamReader(process.getInputStream()));
			String line = bufferedreader.readLine();
			// 筛选出mac地址
			for(;line != null;) {
				String nextLine = bufferedreader.readLine();
				if(line.indexOf("Physical Address") > 0){ 
					int i = line.indexOf("Physical Address") + 36; 
					s = line.substring(i); 
					break; 
				}
				line = nextLine; 
			}
			bufferedreader.close();
			process.waitFor();
		} catch(Exception exception) {
			s = "";
		}
		return s.trim();
	}
	public static void main(String[] args){ 
		// 显示Mac地址在命令行界面
		System.out.println(MacAddressAccess.getMyMac());
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -