Java获取mac地址的方法

网友投稿 182 2023-07-31


Java获取mac地址的方法

本文实例讲述了java获取mac地址的方法。分享给大家供大家参考。具体如下:

/*

* GetMacAddress .java

*

* description:get Mac addreess

*

* @author hadeslee

*

* Created on 2007-9-27, 9:11:15

*

* To change tuSDFxLblMhis 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;

/**

*

*/

http://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程序设计有所帮助。


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:java实现从网上下载图片到本地的方法
下一篇:Java实现Html转Pdf的方法
相关文章

 发表评论

暂时没有评论,来抢沙发吧~