当前位置:首页 » 编程语言 » java序列号获取

java序列号获取

发布时间: 2025-05-06 23:18:40

1. java 怎么获取 U盘的序列号

这种一般是C去获取。java用jni或者command 调用。

2. java代码怎么获取数字的证书那一串20位指纹

通过JAVA来读取数字证书的方法获取20位指纹:
CARead.java文件代码:
public class CARead extends JPanel {
private String CA_Name;
private String CA_ItemData[][] = new String[9][2];
private String[] columnNames = { "证书字段标记", "内容" };
public CARead(String CertName) {
CA_Name = CertName;
/* 三个Panel用来显示证书内容 */
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panelNormal = new JPanel();
tabbedPane.addTab("普通信息", panelNormal);
JPanel panelAll = new JPanel();
panelAll.setLayout(new BorderLayout());
tabbedPane.addTab("所有信息", panelAll);
JPanel panelBase64 = new JPanel();
panelBase64.setLayout(new BorderLayout());
tabbedPane.addTab("Base64编码形式的信息", panelBase64);
/野姿* 读取证书常规信息 */
Read_Normal(panelNormal);
/* 读取证书文件字符串表示内容 */
Read_Bin(panelAll);
/* 以Base64编码颂庆绝形式读取证书文件的信息 */
Read_Raw(panelBase64);
tabbedPane.setSelectedIndex(0);
setLayout(new GridLayout(1, 1));
add(tabbedPane);
}
private int Read_Normal(JPanel panel) {
String Field;
try {
CertificateFactory certificate_factory = CertificateFactory
.getInstance("X.509");
FileInputStream file_inputstream = new FileInputStream(CA_Name);
X509Certificate x509certificate = (X509Certificate) certificate_factory
.generateCertificate(file_inputstream);
Field = x509certificate.getType();
CA_ItemData[0][0] = "类型";
CA_ItemData[0][1] = Field;
Field = Integer.toString(x509certificate.getVersion());
CA_ItemData[1][0] = "版本";
CA_ItemData[1][1] = Field;
Field = x509certificate.getSubjectDN().getName();
CA_ItemData[2][0] = "标题";
CA_ItemData[2][1] = Field;
Field=x509certificate.getNotBefore().toString();//得到开始有效日期
CA_ItemData[3][0] = "开始有效日期";
CA_ItemData[3][1] = Field;
Field=x509certificate. getNotAfter().toString();//得到截止日期
CA_ItemData[4][0] = "截差槐止日期";
CA_ItemData[4][1] = Field;
Field=x509certificate.getSerialNumber().toString(16);//得到序列号
CA_ItemData[5][0] = "序列号";
CA_ItemData[5][1] = Field;
Field=x509certificate.getIssuerDN().getName();//得到发行者名
CA_ItemData[6][0] = "发行者名";
CA_ItemData[6][1] = Field;
Field=x509certificate.getSigAlgName();//得到签名算法
CA_ItemData[7][0] = "签名算法";
CA_ItemData[7][1] = Field;
Field=x509certificate.getPublicKey().getAlgorithm();//得到公钥算法
CA_ItemData[8][0] = "公钥算法";
CA_ItemData[8][1] = Field;
//关闭输入流对象
file_inputstream.close();
final JTable table = new JTable(CA_ItemData, columnNames);
TableColumn tc = null; //表格列控制
tc = table.getColumnModel().getColumn(1);//得到表头
tc.setPreferredWidth(600);//设置宽度
panel.add(table);//增加到布局面板
} catch (Exception exception) {
exception.printStackTrace(); //异常捕获、
return -1;
}
return 0;
}
//读取二进制指纹文件
private int Read_Bin(JPanel panel) {
try {
FileInputStream file_inputstream = new FileInputStream(CA_Name);
DataInputStream data_inputstream = new DataInputStream(
file_inputstream);
CertificateFactory certificatefactory = CertificateFactory
.getInstance("X.509");
byte[] bytes = new byte[data_inputstream.available()];
data_inputstream.readFully(bytes);
ByteArrayInputStream s = new ByteArrayInputStream(bytes);
JEditorPane Cert_EditorPane;
Cert_EditorPane = new JEditorPane();
X509Certificate cert=null;
//遍历得到所有的证书属性
if (s.available() > 0)
{
cert = (X509Certificate) certificatefactory .generateCertificate(s);
Cert_EditorPane.setText(cert.toString());
}
Cert_EditorPane.disable();
JScrollPane edit_scroll = new JScrollPane(Cert_EditorPane);
panel.add(edit_scroll);
file_inputstream.close();
data_inputstream.close();
} catch (Exception exception) {
exception.printStackTrace();
return -1;
}
return 0;
}
private int Read_Raw(JPanel panel) {
try {
JEditorPane Cert_EditorPane = new JEditorPane();
StringBuffer strBuffer =new StringBuffer();
File inputFile = new File(CA_Name);
FileReader in = new FileReader(inputFile);
char[] buf = new char[2000];
int len = in.read(buf, 0, 2000);
for (int i = 1; i < len; i++) {
strBuffer.append(buf[i]);
}
in.close();
Cert_EditorPane.setText(strBuffer.toString());
Cert_EditorPane.disable();
JScrollPane edit_scroll = new JScrollPane(Cert_EditorPane);
panel.add(edit_scroll);
} catch (Exception exception) {
exception.printStackTrace();
return -1;
}
return 0;
}
}

3. 请教高手:java如何读取硬盘的序列号

以下是JAVA获取硬盘序列号的一种方法,仅供参考:

StringHDserialnumber=getHdSerialInfo();
(){
Stringline="";
StringHdSerial="";//定义变量硬盘序列号
try{
Processproces=Runtime.getRuntime().exec("cmd/cdirc:");//获取命令行参数
BufferedReaderbuffreader=newBufferedReader(
newInputStreamReader(proces.getInputStream()));
while((line=buffreader.readLine())!=null){
if(line.indexOf("卷的序列号是")!=-1){//读取参数并获取硬盘序列号
HdSerial=line.substring(line.indexOf("卷的序列号是")
+"卷的序列号是".length(),line.length());
break;
//System.out.println(HdSerial);
}
}
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
returnHdSerial;//返回硬盘序列号卷的序列非物理
}

4. 跪求在JAVA里如何获得CPU的序列号,和硬盘的序列号。

利用Runtime call操作系统的命令,具体的命令取决于不同的操作系统,注意不要调用Runtime.getRuntime().exec(String)接口,要用Runtime.getRuntime().exec(String[])这个接口,不然复杂命令的执行会有问题。例子如下(拿cpu个数,其他类似):
定义命令:
WindowsCmd ="cmd.exe /c echo %NUMBER_OF_PROCESSORS%";//windows的特殊
SolarisCmd = {"/bin/sh", "-c", "/usr/sbin/psrinfo | wc -l"};
AIXCmd = {"/bin/sh", "-c", "/usr/sbin/lsdev -Cc processor | wc -l"};
HPUXCmd = {"/bin/sh", "-c", "echo \"map\" | /usr/sbin/cstm | grep CPU | wc -l "};
LinuxCmd = {"/bin/sh", "-c", "cat /proc/cpuinfo | grep ^process | wc -l"};

然后判断系统:
os = System.getProperty("os.name").toLowerCase();

根据不同的操作系统call不同的命令。
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class GetMACAddress
{
public String getMACAddress(String ipAddress)
{
String str = "",strMAC = "",macAddress = "";
try
{
Process pp = Runtime.getRuntime().exec("nbtstat -a " + ipAddress);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for(int i = 1;i < 100;i++)
{
str = input.readLine();
if(str != null)
{
if(str.indexOf("MAC Address") > 1)
{
strMAC = str.substring(str.indexOf("MAC Address") + 14,str.length());
break;
}
}
}
}
catch(IOException ex)
{
return "Can't Get MAC Address!";
}
//
if(strMAC.length() < 17)
{
return "Error!";
}
macAddress = strMAC.substring(0,2) + ":"
+ strMAC.substring(3,5) + ":"
+ strMAC.substring(6,8) + ":"
+ strMAC.substring(9,11) + ":"
+ strMAC.substring(12,14) + ":"
+ strMAC.substring(15,17);
//
return macAddress;
}

public static void main(String[] args)
{
GetMACAddress getMACAddress = new GetMACAddress();
System.out.println(getMACAddress.getMACAddress("172.18.8.225"));

try
{
java.lang.Process proc = Runtime.getRuntime().exec("ipconfig /all");
InputStream istr = proc.getInputStream();
byte[] data = new byte[1024];
istr.read(data);
String netdata = new String(data);
System.out.println("Your Mac Address=" + procAll(netdata));
}
catch(IOException e)
{
System.out.println("error=" + e);
}
}

public static String procAll(String str)
{
return procStringEnd(procFirstMac(procAddress(str)));
}

public static String procAddress(String str)
{
int indexof = str.indexOf("Physical Address");
if(indexof > 0)
{
return str.substring(indexof,str.length());
}
return str;
}

public static String procFirstMac(String str)
{
int indexof = str.indexOf(":");
if(indexof > 0)
{
return str.substring(indexof + 1,str.length()).trim();
}
return str;
}

public static String procStringEnd(String str)
{
int indexof = str.indexOf("\r");
if(indexof > 0)
{
return str.substring(0,indexof).trim();
}
return str;
}
}

import java.util.Vector;

class GetNetMAC
{
//网卡物理地址长度
static private final int _physicalLength = 16;

public static void main(String[] args)
{
//output you computer phycail ip address
System.out.println("The MAC Addressis:\t" + getPhysicalAddress());
}

static public String getPhysicalAddress()
{
GetNetMACShell shell = new GetNetMACShell();
String cmd = "cmd.exe /c ipconfig/all";
Vector result;
result = shell.execute(cmd);
return parseCmd(result.toString());
}

//从字符串中解析出所需要获得的字符串
static private String parseCmd(String s)
{
String find = "Physical Address. . . . . . . . . :";
int findIndex = s.indexOf(find);
if(findIndex == -1)
{
return "not find";
}
else
{
return s.substring(findIndex + find.length() + 1,findIndex + find.length() + 1 + _physicalLength);
}
}
}

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.InputStreamReader;
import java.util.Vector;

public class GetNetMACShell
{
private Process process = null;

public Vector execute(String shellCommand)
{
try
{
Start(shellCommand);
Vector vResult = new Vector();
DataInputStream in = new DataInputStream(process.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));

String line;
do
{
line = reader.readLine();
if(line == null)
{
break;
}
else
{
vResult.addElement(line);
}
}
while(true);
reader.close();
return vResult;

}
catch(Exception e)
{
//error
return null;
}
}

public void Start(String shellCommand)
{
try
{
if(process != null)
{
kill();
}
Runtime sys = Runtime.getRuntime();
process = sys.exec(shellCommand);
}
catch(Exception e)
{
System.out.println(e.toString());
}
}

public void kill()
{
if(process != null)
{
process.destroy();
process = null;
}
}
}

试试是否可以:)

热点内容
私募通数据库 发布:2025-05-07 02:06:18 浏览:696
dhcp服务器lan地址 发布:2025-05-07 02:03:54 浏览:204
python的字符串反转 发布:2025-05-07 01:57:57 浏览:119
电脑进制编程 发布:2025-05-07 01:55:50 浏览:674
安卓手机在哪里测网速 发布:2025-05-07 01:49:22 浏览:516
怎么样破解excel密码 发布:2025-05-07 01:48:39 浏览:975
小型迷你存储服务器 发布:2025-05-07 01:32:31 浏览:140
手机配置太高怎么玩低配游戏 发布:2025-05-07 01:25:26 浏览:11
视频压缩用什么软件 发布:2025-05-07 01:25:20 浏览:826
如何看懂汽车电瓶配置 发布:2025-05-07 01:19:12 浏览:323