如何使JAVA编写的软件与硬盘注册绑定?! 我写了一个企业管理软件,如何与计算机的硬盘进行注册绑定,绑定后才能运行该软件,希望高手进行指点一下小弟!谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不是打击你啊,获取硬盘序列号需要系统底层的支持,网上有卖的。关键是那个DLL库,你考虑考虑买一个吧 如果会delphi的话,几分钟就搞定,让后java来调用.不过别人随便把你的class反编译一下,绕过检查.这样的加密也没什么用了. 获取Ethernet Adapter和PPP Adapter的Physical Addressimport java.io.*;import java.util.*;import java.util.regex.*;public class Test { String IPCONFIG_COMMAND_WIN = "ipconfig /all "; boolean realMac = true; String unique = " "; public static String getMacAddress() { Test hwid = new Test(); return hwid.getUnique().trim(); } private String getUnique() { String os = System.getProperty("os.name"); if (os.startsWith("Windows")) { return getUniqueWindows(); } else { return " "; } } private String getUniqueWindows() { // 运行控制台命令,返回结果字符串 String ipConfigResponse = null; try { ipConfigResponse = runConsoleCommand(IPCONFIG_COMMAND_WIN); } catch (IOException e) { e.printStackTrace(); } // 按行分割结果字符串,并循环判断每个字符串直到找出 Mac 地址 StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n"); while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken().trim(); // 获取每行 ": " 后的字符串 int macAddressPosition = line.indexOf(": "); if (macAddressPosition <= 0) { continue; } String macAddressCandidate = line.substring(macAddressPosition + 1) .trim(); // 检查 macAddressCandidate 中内容是否为真实网卡 Mac 地址,根据 Mac 地址计算出唯一标识。 if (isMacAddWin(macAddressCandidate)) { if (realMac == true) { generateUnique(macAddressCandidate); } else { realMac = true; } } } return unique; } /** * 运行控制台命令,返回结果字符串 * * @param command * String * @return String * @throws IOException */ private String runConsoleCommand(String command) throws IOException { Process p = Runtime.getRuntime().exec(command); InputStream stdoutStream = new BufferedInputStream(p.getInputStream()); StringBuffer buffer = new StringBuffer(); while (true) { int c = stdoutStream.read(); if (c == -1) { break; } buffer.append((char) c); } String outputText = buffer.toString(); stdoutStream.close(); return outputText; } /** * 对输入参数进行检查,符合正则表达式的为 windows 平台下有效 Mac 地址 * * @param macAddressCandidate * String * @return boolean */ private boolean isMacAddWin(String macAddressCandidate) { Pattern macPattern = Pattern .compile("[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}"); Matcher m = macPattern.matcher(macAddressCandidate); return m.matches(); } /** * 对输入参数进行检查,符合长度的为 MAC OS X 下有效网卡 Mac 地址 * * @param macAddressCandidate * String * @return boolean */ private boolean isMacAddOSX(String macAddressCandidate) { if (macAddressCandidate.length() != 17) { return false; } else { return true; } } /** * 产生 Unique * * @param macAddress * String */ private void generateUnique(String macAddress) { if (unique == " ") { unique += macAddress; } else { unique += "# "; unique += macAddress; } } public static void main(String[] args) { System.out.println(Test.getMacAddress()); }} AWTUtilities.setWindowOpacity的窗体打成jar包不能半透明 一个JTabbedPane的奇怪问题 请教JAVA包中的基本概念 关于JComboBox的简单问题 vector类型能转换为自定义的类吗? 500 分求 The JasperReports Ultimate Guide.pdf 。 对Java有好多困惑,哪里有好的Java群,大家推荐几个。。。 用java怎么样能删除一个指定目录下的文件? 通过java.net.url提取网页数据但是一直在执行却始终执行不完? java 运行问题 到底哪有可编译的java.c 这种报错怎样解决啊?
不过别人随便把你的class反编译一下,绕过检查.这样的加密也没什么用了.
import java.util.*;
import java.util.regex.*;public class Test {
String IPCONFIG_COMMAND_WIN = "ipconfig /all "; boolean realMac = true; String unique = " "; public static String getMacAddress() {
Test hwid = new Test();
return hwid.getUnique().trim();
} private String getUnique() {
String os = System.getProperty("os.name"); if (os.startsWith("Windows")) {
return getUniqueWindows();
}
else {
return " ";
}
} private String getUniqueWindows() {
// 运行控制台命令,返回结果字符串
String ipConfigResponse = null;
try {
ipConfigResponse = runConsoleCommand(IPCONFIG_COMMAND_WIN);
}
catch (IOException e) {
e.printStackTrace();
} // 按行分割结果字符串,并循环判断每个字符串直到找出 Mac 地址
StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n");
while (tokenizer.hasMoreTokens()) {
String line = tokenizer.nextToken().trim(); // 获取每行 ": " 后的字符串
int macAddressPosition = line.indexOf(": ");
if (macAddressPosition <= 0) {
continue;
}
String macAddressCandidate = line.substring(macAddressPosition + 1)
.trim(); // 检查 macAddressCandidate 中内容是否为真实网卡 Mac 地址,根据 Mac 地址计算出唯一标识。
if (isMacAddWin(macAddressCandidate)) {
if (realMac == true) {
generateUnique(macAddressCandidate);
}
else {
realMac = true;
}
}
} return unique;
} /**
* 运行控制台命令,返回结果字符串
*
* @param command
* String
* @return String
* @throws IOException
*/
private String runConsoleCommand(String command) throws IOException {
Process p = Runtime.getRuntime().exec(command);
InputStream stdoutStream = new BufferedInputStream(p.getInputStream()); StringBuffer buffer = new StringBuffer();
while (true) {
int c = stdoutStream.read();
if (c == -1) {
break;
}
buffer.append((char) c);
}
String outputText = buffer.toString(); stdoutStream.close(); return outputText;
} /**
* 对输入参数进行检查,符合正则表达式的为 windows 平台下有效 Mac 地址
*
* @param macAddressCandidate
* String
* @return boolean
*/
private boolean isMacAddWin(String macAddressCandidate) {
Pattern macPattern = Pattern
.compile("[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}");
Matcher m = macPattern.matcher(macAddressCandidate);
return m.matches();
} /**
* 对输入参数进行检查,符合长度的为 MAC OS X 下有效网卡 Mac 地址
*
* @param macAddressCandidate
* String
* @return boolean
*/
private boolean isMacAddOSX(String macAddressCandidate) {
if (macAddressCandidate.length() != 17) {
return false;
}
else {
return true;
}
} /**
* 产生 Unique
*
* @param macAddress
* String
*/
private void generateUnique(String macAddress) {
if (unique == " ") {
unique += macAddress;
}
else {
unique += "# ";
unique += macAddress;
}
} public static void main(String[] args) {
System.out.println(Test.getMacAddress());
}
}