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;
|
}
|
|
}
|