Java獲取mac地址的方法
更新時間:2015年07月24日 11:44:01 作者:fzhlee
這篇文章主要介紹了Java獲取mac地址的方法,涉及java針對系統(tǒng)硬件及IO操作的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了Java獲取mac地址的方法。分享給大家供大家參考。具體如下:
/*
* GetMacAddress .java
*
* description:get Mac addreess
*
* @author hadeslee
*
* Created on 2007-9-27, 9:11:15
*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test2;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
*/
public class GetMacAddress {
public static String getMACAddress() {
String address = "";
String os = System.getProperty("os.name");
System.out.println(os);
if (os != null && os.startsWith("Windows")) {
try {
ProcessBuilder pb = new ProcessBuilder("ipconfig", "/all");
Process p = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
if (line.indexOf("Physical Address") != -1) {
int index = line.indexOf(":");
address = line.substring(index+1);
break;
}
}
br.close();
return address.trim();
} catch (IOException e) {
}
}
return address;
}
public static void main(String[] args) {
System.out.println("" + Test.getMACAddress());
}
}
希望本文所述對大家的java程序設(shè)計有所幫助。
相關(guān)文章
SpringCloud中的Feign服務(wù)間的調(diào)用詳解
這篇文章主要介紹了SpringCloud中的Feign服務(wù)間的調(diào)用詳解,Feign 是一個聲明式的 REST 客戶端,它能讓 REST 調(diào)用更加簡單,Feign 供了 HTTP 請求的模板,通過編寫簡單的接口和插入注解,就可以定義好 HTTP 請求的參數(shù)、格式、地址等信息,需要的朋友可以參考下2024-01-01
myeclipse創(chuàng)建servlet_動力節(jié)點Java學(xué)院整理
這篇文章主要為大家詳細介紹了myeclipse創(chuàng)建servlet的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07
java向es中寫入數(shù)據(jù)報錯org.elasticsearch.action.ActionReque問題
這篇文章主要介紹了java向es中寫入數(shù)據(jù)報錯org.elasticsearch.action.ActionReque問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11
詳解Spring中@Autowired注解是如何實現(xiàn)的
在使用java?config的過程當中,我們不可避免地會有各種各樣的注解打交道,其中,我們使用最多的注解應(yīng)該就是@Autowired注解了,這篇文章就來和大家聊聊它到底怎么實現(xiàn)的吧2023-07-07

