本方法主要用來限制系統在其他的機器上運行
package com
import java
import java
import java
public class NetID {
String IPCONFIG_COMMAND_WIN =
boolean realMac = true;
String unique =
public static String getMacAddress() {
NetID hwid = new NetID();
return hwid
}
private String getUnique() {
String os = System
if (os
return getUniqueWindows();
}else {
return
}
}
private String getUniqueWindows() {
String ipConfigResponse = null;
try {
ipConfigResponse = runConsoleCommand(IPCONFIG_COMMAND_WIN);
}
catch (IOException e) {
e
}
StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse
while (tokenizer
String line = tokenizer
int macAddressPosition = line
if (macAddressPosition <=
continue;
}
String macAddressCandidate = line
trim();
if (isMacAddWin(macAddressCandidate)) {
if (realMac == true) {
generateUnique(macAddressCandidate);
}
else {
realMac = true;
}
}
}
return unique;
}
private String runConsoleCommand(String command) throws IOException {
Process p = Runtime
InputStream stdoutStream = new BufferedInputStream(p
StringBuffer buffer = new StringBuffer();
while (true) {
int c = stdoutStream
if (c ==
break;
}
buffer
}
String outputText = buffer
stdoutStream
return outputText;
}
private boolean isMacAddWin(String macAddressCandidate) {
Pattern macPattern = pile(
Matcher m = macPattern
return m
}
private boolean isMacAddOSX(String macAddressCandidate) {
if (macAddressCandidate
return false;
}
else {
return true;
}
}
private void generateUnique(String macAddress) {
if (unique ==
unique += macAddress;
}
else {
unique +=
unique += macAddress;
}
}
public static void main(String [] args) {
System
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25985.html