java 取cpuid、主板id、硬盘id、mac地址
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
public class HardWareUtils {
/**
* 获取主板序列号
*
* @return
*/
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();
}
/**
* 获取硬盘序列号
*
* @param drive
* 盘符
* @return
*/
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();
}
/**
* 获取CPU序列号
*
* @return
*/
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";
// + " exit for \r\n" + "Next";
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();
}
/**
* 获取MAC地址
*/
public static String getMac(){
String result = "";
try {
Process process = Runtime.getRuntime().exec("ipconfig /all");
InputStreamReader ir = new InputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line;
while ((line = input.readLine()) != null)
if (line.indexOf("Physical Address") > 0) {
String MACAddr = line.substring(line.indexOf("-") - 2);
result=MACAddr;
}
} catch (java.io.IOException e) {
System.err.println("IOException " + e.getMessage());
}
return result;
}
public static void main(String[] args) {
System.out.println("CPU SN:"+HardWareUtils.getCPUSerial());
System.out.println("主板 SN:"+HardWareUtils.getMotherboardSN());
System.out.println("C盘 SN:"+HardWareUtils.getHardDiskSN("c"));
System.out.println("MAC SN:"+HardWareUtils.getMac());
}
}
java 取cpuid、主板id、硬盘id、mac地址相关推荐
- Java获取局域网中所有ip和Mac地址
Java获取局域网中所有ip和Mac地址 定义一个Util public class IpAndMacUtil {/*** 获取本机Mac地址* @param ia* @return* @throws ...
- java 获取 ip mac_Java获取客户端ip mac地址
欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入 最近做一个安全系统,需要对用户的 ip 和 mac 地址进行验证,这里用到获取客户端ip和mac地址的两个方法,留存. 1. ...
- Visual Studio 2022 计算机基本信息采集(硬盘序列号 Mac地址 IP地址)
步骤 1.在 VS 开发工具中新建项目,工程类型为"Windows 窗 体应用程序",如图所示. 2.界面元素设计,在工程的界面设计视图中,使用界面设计工具箱,对应用 程序的界面进 ...
- Java获取客户端(浏览器)的MAC地址
1.获取IP方式 public static String getIpAddress(HttpServletRequest request) {String ip = request.getHeade ...
- java 以太网_java怎样获取以太网的MAC地址
展开全部 读取ipconfig/all里面的内容: public static String checkPhysicalAddress() { String physicalAddress =&quo ...
- java 取磁盘阵列容量_硬盘阵列 Raid 的区别及容量计算方式
0x01 Raid是什么 RAID(Redundant Array of Independent Disk 独立冗余磁盘阵列)技术是加州大学伯克利分校1987年提出,最初是为了组合小的廉价磁盘来代替大 ...
- python获取本机 ip地址、mac地址(物理地址)、计算机名、硬盘序列号、CPU序列号、主板序列号、bios序列号、bios uuid号
文章目录 python获取本机IP地址.mac地址(物理地址).计算机名 物理地址 计算机名.ip地址 硬盘序列号 CPU序列号 主板序列号 bios序列号 bios uuid号 python获取本机 ...
- Java获取客户端mac地址
问题: 项目中需要实现一个功能,在用户登录的时候,要求系统账号和计算机绑定,只有绑定的账号才可以登录,并且每个账号只能绑定一台计算机. 解决方案: 通过请求IP获取mac地址,然后将账号与mac地址进 ...
- 华为数通笔记-MAC地址
MAC简介 MAC基本概念 MAC(Media Access Control)地址用来定义网络设备的位置.MAC地址由48比特长.12位的16进制数字组成,其中从左到右开始,0到23bit是厂商向IE ...
最新文章
- 联想S820 MIUI刷机包 MIUI 4.4.30 流畅执行 在线主题破解
- 关于“数据可视化思考者”的8条军规
- 将 Sidecar 容器带入新的阶段
- 剑指offer——不能被继承的类
- Promise 最完整介绍与实现解密
- jq分页 不刷新页面_滑动无限加载和分页哪个对搜索引擎更友好呢?
- Material Dialogs
- 第九届河南理工大学算法程序设计大赛 正式赛(部分题解)
- 安卓加密软件_安卓视频加密软件使用哪个好?哪个好用?
- html修改字体大小菜鸟,HTML字体大小颜色
- 淘宝无货源自动群控软件一键铺货接口对接说明
- WPF:新手入门教程
- Iframe背景透明
- 如何在Excel中快速调整列宽
- 小米(MIUI)ROOT线刷教程
- 查找FB15k-237 entity id对应实体数据
- 几何光学学习笔记(30)-6.5光通量和光亮度在光学系统中的传递、像面光照度
- 汉诺塔问题(非常简单明了的解析)
- html中siblings方法,siblings()
- 无线设置时服务器无响应怎么办,无线路由器怎么设置服务器未响应