java支持跨平台获取cpuid、主板id、硬盘id、mac地址 (兼容windows、Linux)
windows:
package cn.net.comsys.helper.system.info; 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()); } } |
Linux:
命令:
0、查看CPUID:dmidecode -t processor | grep 'ID'
1、查看服务器型号:dmidecode | grep 'Product Name'
2、查看主板的序列号:dmidecode |grep 'Serial Number'
3、查看系统序列号:dmidecode -s system-serial-number
4、查看内存信息:dmidecode -t memory
5、查看OEM信息:dmidecode -t 11
java支持跨平台获取cpuid、主板id、硬盘id、mac地址 (兼容windows、Linux)的更多相关文章
- PHP中获取内网用户MAC地址(WINDOWS/linux)的实现代码
做一个内网根据MAC地址自动登录的应用,在WINDOW 2003可以正常使用,函数如下 复制代码 代码如下: function ce_getmac() { if(PHP_OS == 'WINNT' ...
- C#/VB.NET 获取电脑属性(硬盘ID、硬盘容量、Cpu序列号、MAC地址、系统类型)
在开发过程中,经常需要获取电脑的一些属性,如获取硬盘ID/CPU序列号/MAC地址作为来加密字符串. 1.硬盘 在我查看网上一些文档时,发现很多人对硬盘序列号很模糊~ 什么叫硬盘序列号?指的是作为一个 ...
- C# 获取本机CPU序列号,MAC地址,硬盘ID,本机IP地址,计算机名,物理内存,PC类型
首先引入服务 然后 调用 本文转载自http://blog.sina.com.cn/s/blog_7eeb43210101hf7f.html public class Computer { publi ...
- Java获取本机的IP与MAC地址
有些机器有许多虚拟的网卡,获取IP地址时会出现一些意外,所以需要一些验证: // 获取mac地址 public static String getMacAddress() { try { Enumer ...
- C# CPU,硬盘,mac地址灯本地信息查询
public class Computer { public static string CpuID; //1.cpu序列号 public static string MacAddress; //2. ...
- 获取客户机的ip和mac地址
只获取clientIP package com.ppms.utils; import javax.servlet.http.HttpServletRequest; /** * Created by l ...
- 使用ARP获取局域网内设备IP和MAC地址
根据Arp列表数据,查询本地设备在线状态 使用 arp -a 获得所有内网地址,首先看Mod对象 public struct MacIpPair { public string HostName; p ...
- iOS开发——获取手机当前WiFi名和MAC地址
获取手机WiFi信息. iOS9以前的方法,还是能用,警告就警告吧!iOS9以后使用的是苹果最新的API框架,NetworkExtension/NEHotspotHelper.h,这个框架,第一次开放 ...
- C#获取路由器外网IP,MAC地址
C#实现的获取路由器MAC地址,路由器外网地址.对于要获取路由器MAC地址,一定需要知道路由器web管理系统的用户名和密码.至于获取路由器的外网IP地址,可以不需要知道路由器web管理系统的用户名和密 ...
随机推荐
- Oracle索引梳理系列(五)- Oracle索引种类之表簇索引(cluster index)
版权声明:本文发布于http://www.cnblogs.com/yumiko/,版权由Yumiko_sunny所有,欢迎转载.转载时,请在文章明显位置注明原文链接.若在未经作者同意的情况下,将本文内 ...
- SQL Server自动化运维系列——监控性能指标脚本(Power Shell)
需求描述 一般在生产环境中,有时候需要自动的检测指标值状态,如果发生异常,需要提前预警的,比如发邮件告知,本篇就介绍如果通过Power shell实现状态值监控 监控值范围 根据经验,作为DBA一般需 ...
- spring cron表达式
其他参考资料 http://www.blogjava.net/hao446tian/archive/2012/02/13/369872.html http://blog.sina.com.cn/s/b ...
- openstack中的身份管理
原文:http://blog.csdn.net/xxfigo/article/details/8785748 原作者关于openstack的一系列文章http://blog.csdn.net/xxfi ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- oracle异常(-)
一.概述异常分成三大类:预定义异常.非预定义异常.自定义异常处理方法分为:直接抛出异常.内部块处理异常.游标处理异常 预定义异常:由PL/SQL定义的异常.由于它们已在standard包中预定义了,因 ...
- Struts2 Ajax校验
Ajax(Asynchronous javascript and xml):异步刷新技术 技术组成: CSS + xml +JavaScript +DOM Ajax核心对象: XMLHttpRequ ...
- Google Material Design的图标字体使用教程
使用教程 1. 打开Material icons下载页 2. 选择要下载的图标 (目前不能多选>_<) 3.选择要下载的格式即可 图标字体使用教程 [方法一] STEP 1: 引入字体文件 ...
- 激活windows7 企业版小记
问题:状态不可用 1)控制面板->管理工具->服务,启动SPP Notification Service和Software Protection两项服务后 重启计算机,仍然提示状态不可用. ...
- 第二天----列表、元组、字符串、算数运算、字典、while
列表 列表是最常用的Python数据类型,它可以作为一个方括号内的逗号分隔值出现. 基本操作: 索引切片追加删除长度切片循环包含 创建.查看列表: 列表中的数字不要加引号,列表的索引从0开始: lis ...