-
Notifications
You must be signed in to change notification settings - Fork 6
Capture Interface type, motherboard model #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Avinash1423
wants to merge
2
commits into
JDiskMark:dev
Choose a base branch
from
Avinash1423:interfaceAndMotherboard
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Random; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
| import javax.swing.filechooser.FileSystemView; | ||
|
|
||
| /** | ||
|
|
@@ -49,7 +51,7 @@ static public boolean deleteDirectory(File path) { | |
| * @param min Minimum value | ||
| * @param max Maximum value. Must be greater than min. | ||
| * @return Integer between min and max, inclusive. | ||
| * @see java.util.Random#nextInt(int) | ||
| * @see Random#nextInt(int) | ||
| */ | ||
| public static int randInt(int min, int max) { | ||
|
|
||
|
|
@@ -243,16 +245,29 @@ public static DiskUsageInfo getDiskUsage(String diskPath) throws IOException, In | |
| } | ||
|
|
||
| public static String getPartitionId(Path path) { | ||
| if (System.getProperty("os.name").startsWith("Windows")) { | ||
| String driveLetter = UtilOs.getDriveLetterWindows(path); | ||
| return driveLetter; | ||
| } else { | ||
|
|
||
| String os=System.getProperty("os.name"); | ||
|
|
||
| if (os.startsWith("Windows")) { | ||
| return UtilOs.getDriveLetterWindows(path); | ||
| } | ||
| if (os.startsWith("Mac")) { | ||
| String partitionPath=UtilOs.getDeviceFromPathMacOs(path); | ||
| if(partitionPath.startsWith("/dev/")){ | ||
| return partitionPath.substring("/dev/".length()); | ||
| } | ||
| return partitionPath; | ||
| } | ||
|
|
||
| else if (os.startsWith("Linux")) { | ||
| String partitionPath = UtilOs.getPartitionFromFilePathLinux(path); | ||
| if (partitionPath.contains("/dev/")) { | ||
| return partitionPath.split("/dev/")[1]; | ||
| } | ||
| return partitionPath; | ||
| } | ||
|
|
||
| return "Os Not Found"; | ||
| } | ||
|
|
||
| public static String getJvmInfo() { | ||
|
|
@@ -273,4 +288,177 @@ public static String getProcessorName() { | |
| } | ||
| return "processor name unknown"; | ||
| } | ||
|
|
||
| /** | ||
| * Get the motherboard / baseboard name of the current system. | ||
| * | ||
| * This method executes OS-specific system commands to retrieve | ||
| * motherboard identification information. | ||
| * | ||
| * Commands used: | ||
| * | ||
| * Windows: | ||
| * wmic baseboard get Product | ||
| * | ||
| * Example output: | ||
| * Product | ||
| * B450M PRO-VDH MAX | ||
| * | ||
| * Linux: | ||
| * cat /sys/devices/virtual/dmi/id/board_name | ||
| * | ||
| * Example output: | ||
| * B450M PRO-VDH MAX | ||
| * | ||
| * macOS: | ||
| * system_profiler SPHardwareDataType | ||
| * | ||
| * Example output snippet: | ||
| * Model Identifier: MacBookPro15,2 | ||
| * | ||
| * Note: | ||
| * - macOS does not expose a direct motherboard name. | ||
| * - For macOS, the "Model Identifier" is returned instead. | ||
| * | ||
| * @return motherboard name as a String, or null if unavailable | ||
| */ | ||
| public static String getMotherBoardName() { | ||
|
|
||
| Process process = null; | ||
|
|
||
| try { | ||
| if (App.os.startsWith("Windows")) { | ||
| process = new ProcessBuilder("wmic", "baseboard", "get", "Product").start(); | ||
| } else if (App.os.contains("Linux")) { | ||
| process = new ProcessBuilder("cat", "/sys/devices/virtual/dmi/id/board_name").start(); | ||
jamesmarkchan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else if (App.os.startsWith("Mac OS")) { | ||
| process = new ProcessBuilder("system_profiler", "SPHardwareDataType").start(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| } catch (IOException e) { | ||
| Logger.getLogger(Util.class.getName()) | ||
| .log(Level.FINE, "Unable to get Motherboard Name", e); | ||
| return null; | ||
| } | ||
|
|
||
| // If no command was set (unsupported OS) | ||
| if (process == null) { return null; } | ||
|
|
||
| try (BufferedReader reader = | ||
| new BufferedReader(new InputStreamReader(process.getInputStream()))) { | ||
|
|
||
| StringBuilder builder = new StringBuilder(); | ||
| String line; | ||
|
|
||
| while ((line = reader.readLine()) != null) { | ||
|
|
||
| line=line.trim(); | ||
|
|
||
| // If OS is mac return Model Identifier as MotherBoard name is not explicitly provided | ||
| if (line.startsWith("Model Identifier:")) { | ||
|
|
||
| return line.split(":",2)[1].trim(); | ||
| } | ||
|
|
||
| if (line.equalsIgnoreCase("Product")) { continue;} | ||
| builder.append(line).append(" "); | ||
| } | ||
|
|
||
| return builder.toString().trim(); | ||
|
|
||
| } catch (IOException e) { | ||
| Logger.getLogger(Util.class.getName()) | ||
| .log(Level.FINE, "Unable to read Motherboard Name", e); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get the physical interface (bus / transport) type of a disk or partition. | ||
| * | ||
| * This method determines the underlying storage interface (e.g. SATA, NVMe, | ||
| * USB) by executing OS-specific system commands and parsing their output. | ||
| * | ||
| * Commands used: | ||
| * | ||
| * Windows: | ||
| * powershell -Command | ||
| * Get-Partition -DriveLetter <partitionId> | Get-Disk | Select -Expand BusType | ||
| * | ||
| * Example output: | ||
| * SATA | ||
| * NVMe | ||
| * USB | ||
| * | ||
| * Linux: | ||
| * lsblk -d -o TRAN /dev/<partitionId> | ||
| * | ||
| * Example output: | ||
| * TRAN | ||
| * sata | ||
| * | ||
| * macOS: | ||
| * diskutil info <partitionId> | ||
| * | ||
| * Example output snippet: | ||
| * Protocol: SATA | ||
| * | ||
| * Notes: | ||
| * - On Windows, the BusType field is returned. | ||
| * - On Linux, the TRAN (transport) column is used. | ||
| * - On macOS, the interface type is parsed from the "Protocol" field. | ||
| * | ||
| * @param partitionId drive letter (Windows) or device identifier (Linux/macOS) | ||
| * @return interface type as a String, or "OS not supported" if unavailable | ||
| */ | ||
| public static String getInterfaceType(String partitionId){ | ||
| Process process = null; | ||
|
|
||
| try { | ||
| if (App.os.startsWith("Windows")) { | ||
| process = new ProcessBuilder( "powershell", "-Command", "Get-Partition -DriveLetter " + partitionId + " | Get-Disk | Select -Expand BusType").start(); | ||
| } else if (App.os.contains("Linux")) { | ||
| process = new ProcessBuilder("lsblk", "-d", "-o", "TRAN", "/dev/" + partitionId).start(); | ||
| } else if (App.os.startsWith("Mac OS")) { | ||
| process = new ProcessBuilder("diskutil", "info", partitionId).start(); | ||
| } | ||
| } catch (IOException e) { | ||
| Logger.getLogger(Util.class.getName()) | ||
| .log(Level.FINE, "Unable to get Interface Type", e); | ||
| return "OS not supported"; | ||
| } | ||
|
|
||
| if (process == null) { return "OS not supported"; } | ||
|
|
||
| try (BufferedReader reader = | ||
| new BufferedReader(new InputStreamReader(process.getInputStream()))) { | ||
|
|
||
| String line; | ||
|
|
||
| while ((line = reader.readLine()) != null) { | ||
|
|
||
| line = line.trim(); | ||
|
|
||
| if (line.isEmpty()) { continue;} | ||
|
|
||
| if (line.equalsIgnoreCase("InterfaceType") || line.equalsIgnoreCase("TRAN")|| line.equalsIgnoreCase("NAME")) { continue;} | ||
|
|
||
| // In case of MacOs parse the output for interface type | ||
| if (line.startsWith("Protocol:")) { | ||
|
|
||
| return line.split(":",2)[1].trim(); | ||
| } | ||
|
|
||
| return line; | ||
|
|
||
| } | ||
|
|
||
| } catch (IOException e) { | ||
| Logger.getLogger(Util.class.getName()) | ||
| .log(Level.FINE, "Unable to read Interface Type", e); | ||
| return "OS not supported"; | ||
| } | ||
|
|
||
| return "OS not supported"; | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i got this