java获取mac和机器码,注册码的实现、CPU序列号

CPU序列号:

 

  1. package test;  
  2.   
  3. import java.io.IOException;  
  4. import java.util.Scanner;  
  5.   
  6. public class CPUTest {  
  7.   
  8.     /** 
  9.      * @param args 
  10.      * @throws IOException  
  11.      */  
  12.     public static void main(String[] args) throws IOException {  
  13.         // TODO Auto-generated method stub  
  14.         long start = System.currentTimeMillis();  
  15.         Process process = Runtime.getRuntime().exec(  
  16.                 new String[] { "wmic""cpu""get""ProcessorId" });  
  17.         process.getOutputStream().close();  
  18.         Scanner sc = new Scanner(process.getInputStream());  
  19.         String property = sc.next();  
  20.         String serial = sc.next();  
  21.         System.out.println(property + ": " + serial);  
  22.            
  23.         System.out.println("time:" + (System.currentTimeMillis() - start));  
  24.   
  25.     }  
  26.   
  27. }  

  结果输出是这样的   

          其实就是用Runtime.getRuntime().exec 执行一个指令而已。。

      想知道结果是否是准确的 , 可以在DOS下面测试  首先windows键+R键 打开运行框 ,然后输入cmd 打开DOS 。然后输入   wmic cpu get ProcessorId   

      这次的结果任然是    

 

      Runtime.getRuntime().exec 真的很强大啊,直接可以取得当前JVM的运行时环境,然后通过exec执行传入的命令参数,Runtime.exec还可以做其他的事情,比如说直接打开一个文件。。不过在这里我就不在做了,有兴趣的小伙伴可以自己去试试看。。。

转载自:https://blog.csdn.net/y353027520dx/article/details/42494721

 

java获取mac和机器码,注册码的实现

package util;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import org.hyperic.sigar.NetFlags;
import org.hyperic.sigar.NetInterfaceConfig;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;

/**
 * java获取mac和机器码,注册码的实现
 * 
 */
public class AuthorizationUtils {
	private static final int SPLITLENGTH = 4;
	private static final String SALT = "yunshouhu";

	public static void main(String args[]) throws Exception {
		String code = getMachineCode();

		System.out.println("code:" + code);

		String authCode = auth(code);
		System.out.println("机器码:" + code);
		System.out.println("注册码:" + authCode);

		// System.out.println("mac:"+getMac());
		// System.out.println("mac2:"+getMac2());

	}

	private static String getMachineCode() {
		Set<String> result = new HashSet<>();
		String mac = getMac();
		System.out.println("mac:" + getMac());
		result.add(mac);
		Properties props = System.getProperties();
		String javaVersion = props.getProperty("java.version");
		result.add(javaVersion);
		// System.out.println("Java的运行环境版本:    " + javaVersion);
		String javaVMVersion = props.getProperty("java.vm.version");
		result.add(javaVMVersion);
		// System.out.println("Java的虚拟机实现版本:    " +
		// props.getProperty("java.vm.version"));
		String osVersion = props.getProperty("os.version");
		result.add(osVersion);
		// System.out.println("操作系统的版本:    " + props.getProperty("os.version"));

		String code = new Md5PasswordEncoder().encodePassword(
				result.toString(), SALT);
		return getSplitString(code, "-", 4);

	}

	// 使用hyperic-sigar获取mac
	private static String getMac2() throws SigarException {
		Sigar sigar = new Sigar();
		String[] ifaces = sigar.getNetInterfaceList();
		for (String iface : ifaces) {
			NetInterfaceConfig cfg = sigar.getNetInterfaceConfig(iface);
			if (NetFlags.LOOPBACK_ADDRESS.equals(cfg.getAddress())
					|| (cfg.getFlags() & NetFlags.IFF_LOOPBACK) != 0
					|| NetFlags.NULL_HWADDR.equals(cfg.getHwaddr())) {
				continue;
			}
			String mac = cfg.getHwaddr();
			return mac;
		}
		return null;

	}

	public static String auth(String machineCode) {
		String newCode = "(yunshouhuxxx@gmail.com)["
				+ machineCode.toUpperCase() + "](xxx应用级产品开发平台)";
		String code = new Md5PasswordEncoder().encodePassword(newCode, SALT)
				.toUpperCase() + machineCode.length();
		return getSplitString(code);
	}

	private static String getSplitString(String str) {
		return getSplitString(str, "-", SPLITLENGTH);
	}

	private static String getSplitString(String str, String split, int length) {
		int len = str.length();
		StringBuilder temp = new StringBuilder();
		for (int i = 0; i < len; i++) {
			if (i % length == 0 && i > 0) {
				temp.append(split);
			}
			temp.append(str.charAt(i));
		}
		String[] attrs = temp.toString().split(split);
		StringBuilder finalMachineCode = new StringBuilder();
		for (String attr : attrs) {
			if (attr.length() == length) {
				finalMachineCode.append(attr).append(split);
			}
		}
		String result = finalMachineCode.toString().substring(0,
				finalMachineCode.toString().length() - 1);
		return result;
	}

	public static String bytesToHexString(byte[] src) {
		StringBuilder stringBuilder = new StringBuilder("");
		if (src == null || src.length <= 0) {
			return null;
		}
		for (int i = 0; i < src.length; i++) {
			int v = src[i] & 0xFF;
			String hv = Integer.toHexString(v);
			if (hv.length() < 2) {
				stringBuilder.append(0);
			}
			stringBuilder.append(hv);
		}
		return stringBuilder.toString();
	}

	// ‎00-24-7E-0A-22-93
	private static String getMac() {
		try {
			Enumeration<NetworkInterface> el = NetworkInterface
					.getNetworkInterfaces();
			while (el.hasMoreElements()) {
				byte[] mac = el.nextElement().getHardwareAddress();
				if (mac == null)
					continue;

				String hexstr = bytesToHexString(mac);
				return getSplitString(hexstr, "-", 2).toUpperCase();

			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return null;
	}
}

转自:https://blog.csdn.net/earbao/article/details/41484691

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java代码获取myeclipse注册码 package util; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* 如何注册myeclipse 1、菜单myeclipse---->subscription Information 2、window----preferences----myeclipse----subscription 3、有的版本是:myeclipse----subscription */ public class MyEclipseGen { /* myeclipse6.5破解,运行即可得到key */ private static final String LL = "Decompiling this copyrighted software is a violation of both your license agreement and the Digital Millenium Copyright Act of 1998 (http://www.loc.gov/copyright/legislation/dmca.pdf). Under section 1204 of the DMCA, penalties range up to a $500,000 fine or up to five years imprisonment for a first offense. Think about it; pay for a license, avoid prosecution, and feel better about yourself."; public String getSerial(String userId, String licenseNum) { java.util.Calendar cal = java.util.Calendar.getInstance(); cal.add(1, 3); cal.add(6, -1); java.text.NumberFormat nf = new java.text.DecimalFormat("000"); licenseNum = nf.format(Integer.valueOf(licenseNum)); String verTime = new StringBuilder("-").append(new java.text.SimpleDateFormat("yyMMdd").format(cal.getTime())).append("0").toString(); String type = "YE3MP-"; String need = new StringBuilder(userId.substring(0, 1)).append(type).append("300").append(licenseNum).append(verTime).toString(); String dx = new StringBuilder(need).append(LL).append(userId).toString(); int suf = this.decode(dx); String code = new StringBuilder(need).append(String.valueOf(suf)).toString(); return this.change(code); } private int decode(String s) { int i; char[] ac; int j; int k; i = 0; ac = s.toCharArray(); j = 0; k = ac.length; while (j < k) { i = (31 * i) + ac[j]; j++; } return Math.abs(i); } private String change(String s) { byte[] abyte0; char[] ac; int i; int k; int j; abyte0 = s.getBytes(); ac = new char[s.length()]; i = 0; k = abyte0.length; while (i < k) { j = abyte0[i]; if ((j >= 48) && (j <= 57)) { j = (((j - 48) + 5) % 10) + 48; } else if ((j >= 65) && (j <= 90)) { j = (((j - 65) + 13) % 26) + 65; } else if ((j >= 97) && (j <= 122)) { j = (((j - 97) + 13) % 26) + 97; } ac[i] = (char) j; i++; } return String.valueOf(ac); } public MyEclipseGen() { super(); } public static void main(String[] args) { try { System.out.println("please input register name:"); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String userId = null; userId = reader.readLine(); MyEclipseGen myeclipsegen = new MyEclipseGen(); String res = myeclipsegen.getSerial(userId, "5"); System.out.println("Serial:" + res); reader.readLine(); } catch (IOException ex) { } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值