1package com.youkone.tool;
2
3import java.io.BufferedReader;
4import java.io.InputStreamReader;
5import java.io.IOException;
6
7/**
8 * <p>Title: </p>
9 *
10 * <p>Description: </p>
11 *
12 * <p>Copyright: Copyright (c) 2006</p>
13 *
14 * <p>Company: </p>
15 *
16 * @author not attributable
17 * @version 1.0
18 */
19public class MACAddress {
20 public MACAddress() {
21 }
22
23 public static String getMACAddress() {
24
25 String address = "";
26 String os = System.getProperty("os.name");
27 if (os != null && os.startsWith("Windows")) {
28 try {
29 String command = "cmd.exe /c ipconfig /all";
30 Process p = Runtime.getRuntime().exec(command);
31 BufferedReader br =
32 new BufferedReader(
33 new InputStreamReader(p.getInputStream()));
34 String line;
35 while ((line = br.readLine()) != null) {
36 if (line.indexOf("Physical Address") > 0) {
37 int index = line.indexOf(":");
38 index += 2;
39 address = line.substring(index);
40 break;
41 }
42 }
43 br.close();
44 return address.trim();
45 } catch (IOException e) {}
46 }
47 return address;
48 }
49
50
51
52public static void main(String[] args) {
53 System.out.println(""+MACAddress.getMACAddress());
54}
55}
56
2
3import java.io.BufferedReader;
4import java.io.InputStreamReader;
5import java.io.IOException;
6
7/**
8 * <p>Title: </p>
9 *
10 * <p>Description: </p>
11 *
12 * <p>Copyright: Copyright (c) 2006</p>
13 *
14 * <p>Company: </p>
15 *
16 * @author not attributable
17 * @version 1.0
18 */
19public class MACAddress {
20 public MACAddress() {
21 }
22
23 public static String getMACAddress() {
24
25 String address = "";
26 String os = System.getProperty("os.name");
27 if (os != null && os.startsWith("Windows")) {
28 try {
29 String command = "cmd.exe /c ipconfig /all";
30 Process p = Runtime.getRuntime().exec(command);
31 BufferedReader br =
32 new BufferedReader(
33 new InputStreamReader(p.getInputStream()));
34 String line;
35 while ((line = br.readLine()) != null) {
36 if (line.indexOf("Physical Address") > 0) {
37 int index = line.indexOf(":");
38 index += 2;
39 address = line.substring(index);
40 break;
41 }
42 }
43 br.close();
44 return address.trim();
45 } catch (IOException e) {}
46 }
47 return address;
48 }
49
50
51
52public static void main(String[] args) {
53 System.out.println(""+MACAddress.getMACAddress());
54}
55}
56