当前位置: 移动技术网 > IT编程>开发语言>Java > Java获取mac地址的方法

Java获取mac地址的方法

2019年07月22日  | 移动技术网IT编程  | 我要评论

本文实例讲述了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程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网