zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package zhuce;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class RegisterMark {
    public static String getRegister(String s) {
        String s1="",s2="";
        SimpleDateFormat sd=new SimpleDateFormat("yyyy");
        Date d=new Date();
        s+=sd.format(d);
        for(int i=0;i<s.length();i++){
            s1+=(int)s.charAt(i)*(i+1);
        }
        for(int i=0;i<s1.length()/5;i++){
 
            if(i==s1.length()/5-1)
                s2+=s1.substring(i*5,(i+1)*5);
            else 
                s2+=s1.substring(i*5, (i+1)*5)+"-";
        }
 
        return s2;
    }
 
    public static String getMAC() {
        String macResult = null;
        String system_name = System.getProperty("os.name");            
        StringBuffer systemPath = new StringBuffer("");
        if (system_name.indexOf("Windows") > -1) {
            // Windows²Ù×÷ϵͳµÄcmd.exeµÄ¾ø¶Ô·¾¶
            systemPath.append("c:/WINDOWS/system32/cmd.exe");
        }
        if (system_name.indexOf("NT") > -1) {
            // NT²Ù×÷ϵͳµÄcmd.exeµÄ¾ø¶Ô·¾¶
            systemPath.append("c:/WINDOWS/command.com");
        }
        // 
        Process pro = null;
        try {
 
            // Serial Number µÄµÃµ½
            // ´ËÓï¾äÏ൱ÓÚÔÚcmdÏÂÃæÖ´ÐРdirµÄÃüÁî.²¢µÃµ½ÃüÁîÖ´ÐÐÍê±ÏºóµÄÊä³öÁ÷
            pro = Runtime.getRuntime().exec(systemPath.toString() + " /c dir");            
            InputStream input = pro.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(input));
            // ¶ÁÈ¡µÚÒ»ÐÐ
            String message = br.readLine();            
            // Serial Number µÄÁãʱ±äÁ¿
            @SuppressWarnings("unused")
            String serNuResult = null;
            int index = -1;
            // ¶ÁÈ¡ÏÂÒ»ÐÐ
            message = br.readLine();
 
            // MacµØÖ·µÄµÃµ½
            // ´ËÓï¾äÏ൱ÓÚÔÚcmdÏÂÃæÖ´ÐРipconfig/all µÄÃüÁî.²¢µÃµ½ÃüÁîÖ´ÐÐÍê±ÏºóµÄÊä³öÁ÷
            pro = Runtime.getRuntime().exec(systemPath.toString() + " /c ipconfig/all");
            input= pro.getInputStream();
            br = new BufferedReader(new InputStreamReader(input));
            // ¶ÁÈ¡µÚÒ»ÐÐ
//            message = br.readLine();
            // MacµØÖ· µÄÁãʱ±äÁ¿
            
            while (message != null) {
                if ((index = message.indexOf("Physical Address")) > 0) {
                    macResult = message.substring(index + 36).trim();
                    break;
                }
                // ¶ÁÈ¡ÏÂÒ»ÐÐ
                message = br.readLine();
            }
 
        }catch(Exception e){
            e.printStackTrace();
        }
        return macResult;
    }
 
}