java 代码
- /***********************************************************************
- * Module: MACAddress.java
- * Author: danlley
- * Modified: 2006年6月05日 12:45:21
- * Purpose: Defines the Interface ManageCA
- ***********************************************************************/
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.IOException;
- import java.util.ArrayList;
- public class MACAddress {
- public MACAddress() {
- }
- public static ArrayList getMACAddress() {
- ArrayList arrayList=new ArrayList();
- String address = "";
- String os = System.getProperty("os.name");
- if (os != null && os.startsWith("Windows")) {
- try {
- String command = "cmd.exe /c ipconfig /all";
- Process p = Runtime.getRuntime().exec(command);
- BufferedReader br =
- new BufferedReader(
- new InputStreamReader(p.getInputStream()));
- String line;
- while ((line = br.readLine()) != null) {
- if(line.trim().length()>0){
- arrayList.add(line);
- }
- }
- int size=arrayList.size();
- System.out.println("Read from InputStream the List size is : "+size);
- br.close();
- return arrayList;
- } catch (IOException e) {}
- }
- return arrayList;
- }
- public static void main(String[] args) {
- ArrayList arrayList=MACAddress.getMACAddress();
- int size=arrayList.size();
- System.out.println("Get the data from the list the size is : "+size);
- for(int i=0;i0){
- String str=arrayList.get(i).toString().trim();
- int len=str.length();
- int pointIndex=str.indexOf(":");
- //System.out.println("Line "+i+" Len="+len+" pointIndex="+pointIndex+" "+str);
- if(pointIndex>0){
- String subStr=str.substring(pointIndex+1,len).trim();
- int lenSubStr=subStr.length();
- if(lenSubStr>0){
- System.out.println(subStr);
- }
- }
- }
- }
- }
- }