آموزشآموزش Java Swingبرنامه نویسی
بدست آوردن مشخصات سیستم
برای بدست آورن مشخصات سیستم با جزئیات در جاوا میتوانید از کتابخانه oshi استفاده کنید بعد از اضافه کردن این کتابخانه به پروژه برای هر یک از سخت افزارها یا سیستم عامل می توانید از کدهای زیر استفاده کنید
یک پروژه ایجاد کنید بعد از اضافه کردن کتابخانه oshi به پروژه یک فرم جدید ایجاد کرده و به فرم خود Button و TextArea به تعداد مورد نیاز خود اضافه کنید و کد های زیر را برای Button های خود بنویسید
اول کتابخانه ها را فراخوانی کنید
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import oshi.SystemInfo; import oshi.hardware.HardwareAbstractionLayer; import oshi.software.os.OperatingSystem; import java.io.BufferedReader; import java.io.File; import java.io.FileWriter; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.List; import oshi.hardware.CentralProcessor; import oshi.hardware.GlobalMemory; import oshi.hardware.PhysicalMemory; import oshi.software.os.FileSystem; import oshi.software.os.OSFileStore; import oshi.util.FormatUtil; |
CPU Temperature
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea1.append(hal.getSensors().toString()); |
MotherBoard
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea2.append(hal.getComputerSystem().toString()); |
HDD
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea3.append(hal.getDiskStores().toString()); |
Displays
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea4.append(hal.getDisplays().toString()); |
Graphics
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea5.append(hal.getGraphicsCards().toString()); |
Logical Volume
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea11.append(hal.getLogicalVolumeGroups().toString()); |
Ram Size
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea12.append(hal.getMemory().toString()); |
Network IFs
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea13.append(hal.getNetworkIFs().toString()); |
root Pane Check
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea14.append(hal.getNetworkIFs(rootPaneCheckingEnabled).toString()); |
Power Sources
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea15.append(hal.getPowerSources().toString()); |
Processor
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea16.append(hal.getProcessor().toString()); |
Sound Cards
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea17.append(hal.getSoundCards().toString()); |
Usb Devices
1 2 3 |
SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); jTextArea18.append(hal.getUsbDevices(true).toString()); |
Network Params
1 2 3 |
SystemInfo si = new SystemInfo(); OperatingSystem os = si.getOperatingSystem(); jTextArea19.append(os.getNetworkParams().toString()); |
OS Version
1 2 3 |
SystemInfo si = new SystemInfo(); OperatingSystem os = si.getOperatingSystem(); jTextArea20.append(os.getVersionInfo().toString()); |
Available processors (cores)
1 2 |
System.out.println("Available processors (cores): " + Runtime.getRuntime().availableProcessors()); |
Processor info detail
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
SystemInfo systemInfo = new SystemInfo(); HardwareAbstractionLayer hardware = systemInfo.getHardware(); CentralProcessor processor = hardware.getProcessor(); CentralProcessor.ProcessorIdentifier processorIdentifier = processor.getProcessorIdentifier(); System.out.println("Processor Vendor: " + processorIdentifier.getVendor()); System.out.println("Processor Name: " + processorIdentifier.getName()); System.out.println("Processor ID: " + processorIdentifier.getProcessorID()); System.out.println("Identifier: " + processorIdentifier.getIdentifier()); System.out.println("Microarchitecture: " + processorIdentifier.getMicroarchitecture()); System.out.println("Frequency (Hz): " + processorIdentifier.getVendorFreq()); System.out.println("Frequency (GHz): " + processorIdentifier.getVendorFreq() / 1000000000.0); System.out.println("Number of physical packages: " + processor.getPhysicalPackageCount()); System.out.println("Number of physical CPUs: " + processor.getPhysicalProcessorCount()); System.out.println("Number of logical CPUs: " + processor.getLogicalProcessorCount()); |
patitions info
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
SystemInfo systemInfo = new SystemInfo(); OperatingSystem operatingSystem = systemInfo.getOperatingSystem(); FileSystem fileSystem = operatingSystem.getFileSystem(); List<OSFileStore> osFileStores = fileSystem.getFileStores(); for (OSFileStore fileStore : osFileStores) { System.out.println("Description: " + fileStore.getDescription()); System.out.println("Label: " + fileStore.getLabel()); System.out.println("Logical Volume: " + fileStore.getLogicalVolume()); System.out.println("Mount: " + fileStore.getMount()); System.out.println("Name: " + fileStore.getName()); System.out.println("Options: " + fileStore.getOptions()); System.out.println("Type: " + fileStore.getType()); System.out.println("UUID: " + fileStore.getUUID()); System.out.println("Volume: " + fileStore.getVolume()); System.out.println("Free Space: " + FormatUtil.formatBytes(fileStore.getFreeSpace())); System.out.println("Total Space: " + FormatUtil.formatBytes(fileStore.getTotalSpace())); System.out.println("Usable Space: " + FormatUtil.formatBytes(fileStore.getUsableSpace())); } |
ram size
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
SystemInfo systemInfo = new SystemInfo(); HardwareAbstractionLayer hardware = systemInfo.getHardware(); GlobalMemory globalMemory = hardware.getMemory(); long usedMemory = globalMemory.getTotal() - globalMemory.getAvailable(); System.out.println(globalMemory.toString()); System.out.println("Total memory: " + FormatUtil.formatBytes(globalMemory.getTotal())); System.out.println("Available memory: " + FormatUtil.formatBytes(globalMemory.getAvailable())); System.out.println("Used memory: " + FormatUtil.formatBytes(usedMemory)); List<PhysicalMemory> physicalMemories = globalMemory.getPhysicalMemory(); for (PhysicalMemory physicalMemory : physicalMemories) { System.out.println(physicalMemory.toString()); } |
ram brand and slots
1 2 3 4 5 6 7 8 9 10 11 |
SystemInfo systemInfo = new SystemInfo(); HardwareAbstractionLayer hardware = systemInfo.getHardware(); GlobalMemory globalMemory = hardware.getMemory(); List<PhysicalMemory> physicalMemories = globalMemory.getPhysicalMemory(); for (PhysicalMemory physicalMemory : physicalMemories) { System.out.println(physicalMemory.toString()); System.out.println( physicalMemory.toString() + "\n"); } |
MBoard SN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
String result = ""; try { File file = File.createTempFile("GetMBSerial", ".vbs"); file.deleteOnExit(); FileWriter fw = new FileWriter(file); String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery _ \n" + " (\"Select * from Win32_ComputerSystemProduct\") \n" + "For Each objItem in colItems \n" + " Wscript.Echo objItem.IdentifyingNumber \n" + "Next \n"; fw.write(vbs); fw.close(); Process gWMI = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath()); BufferedReader input = new BufferedReader(new InputStreamReader(gWMI.getInputStream())); String line; while ((line = input.readLine()) != null) { result += line; System.out.println(line); } input.close(); } catch (Exception e) { e.printStackTrace(); } result = result.trim(); System.out.println( result + "\n"); |
Host Name
1 2 3 4 5 6 7 8 9 10 |
try { InetAddress inetAddress = InetAddress.getLocalHost(); String hostName = inetAddress.getHostName(); System.out.println("Host Name: " + hostName); } catch (Exception e) { e.printStackTrace(); } |
Ip Address
1 2 3 4 5 6 7 8 9 10 |
try { InetAddress inetAddress = InetAddress.getLocalHost(); String ipAddress = inetAddress.getHostAddress(); System.out.println("IP address: " + ipAddress); } catch (Exception e) { e.printStackTrace(); } |
MAC Address
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
try { InetAddress inetAddress = InetAddress.getLocalHost(); NetworkInterface networkInterface = NetworkInterface.getByInetAddress(inetAddress); byte[] macAddress = networkInterface.getHardwareAddress(); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < macAddress.length; i++) { stringBuilder.append(String.format("%02X%s", macAddress[i], (i < macAddress.length - 1) ? "-" : "")); } System.out.println("MAC address : " + stringBuilder.toString()); } catch (Exception e) { e.printStackTrace(); } |
OS Name
1 2 3 4 5 6 7 8 9 10 |
SystemInfo systemInfo = new SystemInfo(); System.out.println(systemInfo); OperatingSystem operatingSystem = systemInfo.getOperatingSystem(); System.out.println("Operating System: " + operatingSystem.toString()); System.out.println("Family: " + operatingSystem.getFamily()); System.out.println("Manufacturer: " + operatingSystem.getManufacturer()); System.out.println("Number of bits supported by the OS (32 or 64): " + operatingSystem.getBitness()); |