網(wǎng)站首頁 編程語言 正文
public String getMACAddressByWindows() throws Exception {
String result = "";
Process process = Runtime.getRuntime().exec("ipconfig /all");
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"));
int index = -1;
String line;
boolean getInfo = false;
while ((line = br.readLine()) != null) {
if(line.contains("以太網(wǎng)適配器 以太網(wǎng):") || getInfo){
getInfo = true;
index = line.indexOf("物理地址");
if (index >= 0) {
index = line.indexOf(":");
if (index >= 0) {
result = line.substring(index + 1).trim();
break;
}
}
}
}
br.close();
LoggerUtil.info(logger,"Mac address -> {0}",result);
return result;
}
public String getLinuxMACAddress() {
String mac = "";
BufferedReader bufferedReader = null;
Process process = null;
try {
process = Runtime.getRuntime().exec("ip addr");
bufferedReader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line = null;
int index = -1;
while ((line = bufferedReader.readLine()) != null) {
index = line.toLowerCase().indexOf("link/ether");
if (index != -1) {
String[] macs = line.trim().split(" ");
mac = macs[1].trim().toLowerCase();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bufferedReader != null) {
bufferedReader.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
bufferedReader = null;
process = null;
}
LoggerUtil.info(logger,"MAC address -> {0}", mac);
return mac;
}
原文鏈接:https://blog.csdn.net/m0_65014849/article/details/131638358
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-05-08 關(guān)于PyQt5中QtGui.QImage圖片顯示問題解析_python
- 2022-03-29 關(guān)于使用Redisson訂閱數(shù)問題_Redis
- 2022-06-01 C語言詳細(xì)分析常見字符串函數(shù)與模擬實(shí)現(xiàn)_C 語言
- 2023-03-20 C#如何讓winform程序中的輸入文本框保留上次的輸入_C#教程
- 2023-01-17 怎樣保存模型權(quán)重和checkpoint_python
- 2022-11-06 Android?ViewPager2?使用及自定義指示器視圖實(shí)現(xiàn)_Android
- 2022-08-21 利用Python創(chuàng)建第一個(gè)Django框架程序_python
- 2021-12-09 VS2017開發(fā)C語言出現(xiàn)“no_init_all“的解決辦法_C 語言
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支