java获取计算机设备信息的操作

在这里插入图片描述

package com.RuoYi.RuoYiPojo;

import java.applet.Applet;
import java.awt.*;
import java.awt.Graphics;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;

public class HardWareUtils extends Applet {
    public HardWareUtils() throws HeadlessException {
    }

    private static final long serialVersionUID = 1L;


    @Override
    public void paint(Graphics paint) {
        super.paint(paint);
        paint.drawString("获取硬件信息", 10, 10);
        paint.drawString("CPU SN:" + HardWareUtils.getCPUSerial(), 10, 30);
        paint.drawString("主板 SN:" + HardWareUtils.getMotherboardSN(), 10, 50);
        paint.drawString("C盘 SN:" + HardWareUtils.getHardDiskSN("c"), 10, 70);
        paint.drawString("MAC SN:" + HardWareUtils.getMac(), 10, 90);
    }


    /**
     * 获取主板序列号30
     * @return
     * <p>
     */

    public static String getMotherboardSN() {
        String result = "";
        try {
            File file = File.createTempFile("realhowto", ".vbs");
            file.deleteOnExit();
            FileWriter fw = new java.io.FileWriter(file);
            String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"

                    + "Set colItems = objWMIService.ExecQuery _ \n"

                    + " (\"Select * from Win32_BaseBoard\") \n"

                    + "For Each objItem in colItems \n"

                    + " Wscript.Echo objItem.SerialNumber \n"

                    + " exit for ' do the first cpu only! \n" + "Next \n";

            fw.write(vbs);
            fw.close();
            Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
            BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = input.readLine()) != null) {
                result += line;

            }
            input.close();

        } catch (Exception e) {
            e.printStackTrace();

        }
        return result.trim();

    }

    /**
     * 获取硬盘序列号
     *@paramdrive
     * 盘符
     *@return
     * <p>
     */

    public static String getHardDiskSN(String drive) {
        String result = "";
        try {
            File file = File.createTempFile("realhowto", ".vbs");
            file.deleteOnExit();
            FileWriter fw = new java.io.FileWriter(file);


            String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"

                    + "Set colDrives = objFSO.Drives\n"

                    + "Set objDrive = colDrives.item(\""

                    + drive + "\")\n"

                    + "Wscript.Echo objDrive.SerialNumber"; //see note

            fw.write(vbs);
            fw.close();
            Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
            BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = input.readLine()) != null) {
                result += line;

            }
            input.close();

        } catch (Exception e) {
            e.printStackTrace();

        }
        return result.trim();

    }

    /**
     * 101 * 获取CPU序列号102 *103 *@return
     * <p>
     * 104
     */

    public static String getCPUSerial() {
        String result = "";
        try {
            File file = File.createTempFile("tmp", ".vbs");
            file.deleteOnExit();
            FileWriter fw = new java.io.FileWriter(file);
            String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"

                    + "Set colItems = objWMIService.ExecQuery _ \n"

                    + " (\"Select * from Win32_Processor\") \n"

                    + "For Each objItem in colItems \n"

                    + " Wscript.Echo objItem.ProcessorId \n"

                    + " exit for ' do the first cpu only! \n" + "Next \n";
            fw.write(vbs);
            fw.close();
            Process p = Runtime.getRuntime().exec(
                    "cscript //NoLogo " + file.getPath());
            BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = input.readLine()) != null) {
                result += line;
            }
            input.close();
            file.delete();
        } catch (Exception e) {
            e.fillInStackTrace();
        }
        if (result.trim().length() < 1 || result == null) {
            result = "无CPU_ID被读取";
        }
        return result.trim();
    }


    /**
     * 139 * 获取MAC地址
     */

    public static String getMac() {
        try {
            byte[] mac = NetworkInterface.getByInetAddress(InetAddress.getLocalHost()).getHardwareAddress();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < mac.length; i++) {
                if (i != 0) {
                    sb.append("-");
                }
                String s = Integer.toHexString(mac[i] & 0xFF);
                sb.append(s.length() == 1 ? 0 + s : s);
            }
            return sb.toString().toUpperCase();
        } catch (Exception e) {
            return "";
        }

    }


    public static void main(String[] args) throws Exception {
        System.out.println("CPU::" + getCPUSerial());//CPU

        System.out.println("主板::" + getMotherboardSN());//主板

        System.out.println("c盘::" + getHardDiskSN("c"));//c盘

        System.out.println("MAC::" + getMac());//MAC

        String msg = getCPUSerial()
                + getMotherboardSN().replace(".", "")
                + getHardDiskSN("c")
                + getMac().replace("-", "");
        System.out.println("原始数据:" + msg);


        String encode = DesUtils.encode(msg);
        System.out.println("加密:" + encode);
        String decode = DesUtils.decode(encode);
        System.out.println("解密:" + decode);
    }
}

package com.RuoYi.RuoYiPojo;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.security.SecureRandom;

public class DesUtils {

        private static final String DES = "DES";
        private static final String KEY = "4YztMHI7PsT4rLZN";

        private DesUtils() {}

        private static byte[] encrypt(byte[] src, byte[] key) throws Exception {
            SecureRandom sr = new SecureRandom();
            DESKeySpec dks = new DESKeySpec(key);
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
            SecretKey secretKey = keyFactory.generateSecret(dks);
            Cipher cipher = Cipher.getInstance(DES);
            cipher.init(Cipher.ENCRYPT_MODE, secretKey, sr);
            return cipher.doFinal(src);
        }

        private static byte[] decrypt(byte[] src, byte[] key) throws Exception {
            SecureRandom sr = new SecureRandom();
            DESKeySpec dks = new DESKeySpec(key);
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
            SecretKey secretKey = keyFactory.generateSecret(dks);
            Cipher cipher = Cipher.getInstance(DES);
            cipher.init(Cipher.DECRYPT_MODE, secretKey, sr);
            return cipher.doFinal(src);
        }

        private static String byte2hex(byte[] b) {
            String hs = "";
            String temp = "";
            for (int n = 0; n < b.length; n++) {
                temp = (java.lang.Integer.toHexString(b[n] & 0XFF));
                if (temp.length() == 1)
                    hs = hs + "0" + temp;
                else
                    hs = hs + temp;
            }
            return hs.toUpperCase();

        }

        private static byte[] hex2byte(byte[] b) {
            if ((b.length % 2) != 0)
                throw new IllegalArgumentException("length not even");
            byte[] b2 = new byte[b.length / 2];
            for (int n = 0; n < b.length; n += 2) {
                String item = new String(b, n, 2);
                b2[n / 2] = (byte) Integer.parseInt(item, 16);
            }
            return b2;
        }

        private static String decode(String src, String key) {
            String decryptStr = "";
            try {
                byte[] decrypt = decrypt(hex2byte(src.getBytes()), key.getBytes());
                decryptStr = new String(decrypt);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return decryptStr;
        }

        private static String encode(String src, String key){
            byte[] bytes = null;
            String encryptStr = "";
            try {
                bytes = encrypt(src.getBytes(), key.getBytes());
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            if (bytes != null)
                encryptStr = byte2hex(bytes);
            return encryptStr;
        }

        /**
         * 解密
         */
        public static String decode(String src) {
            return decode(src, KEY);
        }

        /**
         * 加密
         */
        public static String encode(String src) {
            return encode(src, KEY);
        }

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java通过ONVIF协议操作摄像头设备的相关官方文档包括: 1. ONVIF官方网站:https://www.onvif.org/ 在ONVIF官方网站上,可以找到ONVIF协议的最新版本和相关文档,包括设备管理、媒体管理、事件管理等模块的接口定义和使用说明。 2. ONVIF Device Test Tool(DTT)官方文档:https://www.onvif.org/profiles/profile-conformance/ ONVIF DTT是用于测试ONVIF协议兼容性的工具,它可以验证设备是否符合ONVIF协议标准,并提供详细的测试报告。官方文档中包含DTT的安装和使用说明,以及测试报告的解释说明。 3. Java ONVIF Library官方文档:https://github.com/milg0/onvif-java-lib/wiki Java ONVIF Library是一个基于Java语言实现的ONVIF协议库,它提供了对ONVIF设备的网络发现、设备信息获取、媒体流控制等功能。官方文档中包含库的安装和使用说明,以及各个接口的参数和用法说明。 4. OpenCV官方文档:https://opencv.org/ OpenCV是一个开源计算机视觉库,它提供了很多用于图像处理和分析的算法和工具。在使用ONVIF协议控制摄像头设备时,可能需要对获取到的视频流进行处理和分析,OpenCV提供了很多有用的功能和工具,官方文档中包含了使用说明和各个算法的参数和用法说明。 总之,要使用Java通过ONVIF协议操作摄像头设备,需要了解ONVIF协议的相关接口和使用方式,以及使用Java ONVIF Library等工具进行开发和测试。同时,对图像处理和分析技术的了解也是必要的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值