1
package com.youkone.tool;
2
3
import java.io.BufferedReader;
4
import java.io.InputStreamReader;
5
import 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
*/
19
public 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
52
public static void main(String[] args) {
53
System.out.println(""+MACAddress.getMACAddress());
54
}
55
}
56

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56
