欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java获取mac地址的方法

程序员文章站 2024-03-05 21:03:49
本文实例讲述了java获取mac地址的方法。分享给大家供大家参考。具体如下: /* * getmacaddress .java * * descriptio...

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