java根据系统参数生成每个计算机的唯一标识。

1. 获取CPU序列号

 /**
* 获取CPU序列号
* @return
* @throws IOException
*/
public static String getCPUSerialNumber() {
String next;
try {
Process process = Runtime.getRuntime().exec(new String[]{"wmic", "cpu", "get", "ProcessorId"});
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String serial = sc.next();
next = sc.next();
} catch (IOException e) {
throw new RuntimeException("获取CPU序列号失败");
}
return next;
}

2.获取 硬盘序列号

 /**
* 获取 硬盘序列号(Windows)
* @return
* @throws IOException
* @throws InterruptedException
*/
public static String getHardDiskSerialNumber() {
try {
Process process = Runtime.getRuntime().exec(new String[]{"wmic", "path", "win32_physicalmedia", "get", "serialnumber"});
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String serial = sc.next();
return sc.next();
} catch (IOException e) {
throw new RuntimeException("获取硬盘序列号失败");
}
}

3. bois版本号(linux)

/**
* bois版本号(linux)
*
* @return
*/
public static String getBoisVersion() {
String result = "";
Process p;
try {
// 管道
p = Runtime.getRuntime().exec("sudo dmidecode -s bios-version");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
result += line;
break;
}
br.close();
} catch (IOException e) {
System.out.println("获取主板信息错误");
}
return result;
}

4. 获取系统序列号(linux)

/**
* 获取系统序列号(linux)
*
* @return
*/
public static String getUUID() {
String result = "";
try {
Process process = Runtime.getRuntime().exec("sudo dmidecode -s system-uuid");
InputStream in;
BufferedReader br;
in = process.getInputStream();
br = new BufferedReader(new InputStreamReader(in));
while (in.read() != -1) {
result = br.readLine();
}
br.close();
in.close();
process.destroy();
System.out.println("获取序列号:"+result);
} catch (Throwable e) {
e.printStackTrace();
}
return result;
}

5.字符串分割

    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));
}
return temp.toString();
}

6. 获取window or linux机器码

 /**
* 获取window or linux机器码
* @return
*/
public static String getWindowNumber(String type){
if (Objects.isNull(type)){
return "";
}
Map<String,Object> codeMap=new HashMap<>(2);
String result = "";
if ("linux".equals(type)){
String boisVersion = getBoisVersion();
codeMap.put("boisVersion",boisVersion);
System.out.println("boisVersion:" + boisVersion);
String uuid = getUUID();
codeMap.put("uuid",uuid);
System.out.println("uuid:" + uuid);
String codeMapStr = JSON.toJSONString(codeMap);
String serials = MD5Util.saltingMD5(codeMapStr, SALT);
result= getSplitString(serials, "-", 4);
}else if ("window".equals(type)){
String processorId = getCPUSerialNumber();
codeMap.put("ProcessorId",processorId);
System.out.println("ProcessorId:" + processorId);
String serialNumber = getHardDiskSerialNumber();
codeMap.put("SerialNumber",serialNumber);
System.out.println("SerialNumber:" + serialNumber);
String codeMapStr = JSON.toJSONString(codeMap);
String serials = MD5Util.saltingMD5(codeMapStr, SALT);
result= getSplitString(serials, "-", 4);
}else { }
return result;
}

7.生成机器码

/**
* 机器码:A45DF6C62F6568B6E0039653EF7FF55F
* @param args
*/
public static void main(String[] args) throws IOException {
String windowNumber = getWindowNumber("window");
System.out.println("机器码:" + windowNumber);
}

java生成机器码的更多相关文章

  1. Java生成和操作Excel文件(转载)

    Java生成和操作Excel文件   JAVA EXCEL API:是一开放源码项目,通过它Java开发人员可以读取Excel文件的内容.创建新的Excel文件.更新已经存在的Excel文件.使用该A ...

  2. 利用JAVA生成二维码

    本文章整理于慕课网的学习视频<JAVA生成二维码>,如果想看视频内容请移步慕课网. 维基百科上对于二维码的解释. 二维条码是指在一维条码的基础上扩展出另一维具有可读性的条码,使用黑白矩形图 ...

  3. Java生成验证码原理(jsp)

     验证码的作用: 验证码是Completely Automated Public Turing test to tell Computers and Humans Apart(全自动区分计算机和人类的 ...

  4. JAVA生成条形码

    1.下载生成条形码所需要的jar包barcode4j.jar: 2.java生成条形码代码 import java.awt.image.BufferedImage;import java.io.Fil ...

  5. Java生成CSV文件实例详解

    本文实例主要讲述了Java生成CSV文件的方法,具体实现步骤如下: 1.新建CSVUtils.java文件: package com.saicfc.pmpf.internal.manage.utils ...

  6. java 生成8位数字作为UID

    java 生成8位数字作为UUID: /*** * 生成uid 8位数字 */public static String generateUID(){ Random random = new Rando ...

  7. java生成随机序列号

    1.java生成随机序列号 String deleteUuid = UUID.randomUUID().toString(); 引用Jar包 //java-uuid-generator-3.1.3.j ...

  8. java生成简单Excel工作薄

    前言: 代码都是建立在实际需求上的,上周做完一个调外部电影券接口的项目,这周产品又要excel表格,大致内容为:券所属影院.图片URL.等信息制作为excel表格,把每次同步过来的数据给他分析. jx ...

  9. 【转】Java生成对应字符串的MD5密码模块

    原文网址:http://www.cnblogs.com/xudong-bupt/archive/2013/05/10/3070899.html (1)一般使用的数据库中都会保存用户名和密码,其中密码不 ...

  10. Java生成文件

    Java生成文件 1.说明 以文件路径作为參数,推断该文件是否存在,若不存在就创建文件.并输出文件路径 2.实现源代码 /** * @Title:BuildFile.java * @Package:c ...

随机推荐

  1. python开头

    python识别的正则模式 coding[:=]\s*([-\w.]+)#coding:utf8   ???不要用 #coding=utf-8#coding:utf-8# -*- coding: ut ...

  2. FastDFS安装(ARM同样支持)

    一.服务器部署规划 服务器IP 部署服务 192.168.*. tracker.storage.nginx 二.数据存储目录 应用 目录 fastdfs /usr/bin nginx /usr/loc ...

  3. java相关部分配置

    一.mybatis逆向工程 ① generator.properties jdbc.driverLocation=D:/testDir/Maven/repository_g/mysql/mysql-c ...

  4. form表单 css的选择器和一些属性以及盒子模型,浮动

    form表单 <form action='' method='' enctype=''> <input type='text'> input:更下type属性就可以得到对应的效 ...

  5. LeetCode 94. 二叉树的中序遍历()

    原题解 题目 约束 题解 方法一 class Solution { public: void inorder(TreeNode* root, vector<int>& res) { ...

  6. 在目标服务器Centos7上安装 GitLab Runner

    1.安装提示: 注意:如果你打算通过gitlab-ci,将项目部署到"目标服务器"上,那么这个GitLab Runner就要提前安装到这个"目标服务器"上 (这 ...

  7. python多线程获取线程执行结果

    In [1]: from threading import Thread def fun(t): """ //执行函数体 //t:时间 """ ...

  8. 【picoCTF]cookies write up

    顾名思义,这一挑战涉及对cookie的简单操作.登录页面会显示一个搜索框,其中包含一个输入字段,用于检查您为其提供的 Cookie 类型. 点击链接,页面如下: 随便在框里输入内容,显示如下: 输出返 ...

  9. leetcode-1072 Flip Columns For Maximum Number of Equal Rows

    Given a matrix consisting of 0s and 1s, we may choose any number of columns in the matrix and flip e ...

  10. 笔精墨妙,妙手丹青,微软开源可视化版本的ChatGPT:Visual ChatGPT,人工智能AI聊天发图片,Python3.10实现

    说时迟那时快,微软第一时间发布开源库Visual ChatGPT,把 ChatGPT 的人工智能AI能力和Stable Diffusion以及ControlNet进行了整合.常常被互联网人挂在嘴边的& ...