Printing My MAC's Serial Number in Java Using Unix Commands

How to get system level information from OSX with java

Maybe SIGAR is of help? It works for a variety of operating systems, including OS X.
https://support.hyperic.com/display/SIGAR/Home

How do I determine OSX Hardware type?

You can query ioreg for the model via ProcessBuilder, as shown here.

Addendum: Similar information may be obtained from the output of system_profiler.

Passing args into a executable Unix file (MacOS)

In this concrete example, three arguments are passed:

  • "bash"
  • "-c"
  • "ioreg -l | awk '/IOPlatformSerialNumber/ { print $4;}'"

Unless you need the shell to interpret your arguments, you can probably do something like this:

ProcessBuilder pb = new ProcessBuilder("/User/me/path/to/Binaryfile/binfile",
"-o xx.xxx.xx.xxx:xxxx", "-u xxxxx", "-p xxxx");

How to get a computer specific ID number using Java

Yes. You can do it without MAC address in both PC as well as linux systems.

I am going to break the process in steps.

Step1: Identify OS
In Your java code, identify the OS used like this

private static String OS = System.getProperty("os.name").toLowerCase();
if(OS.indexOf("win") >= 0)
//your code for windows OS.
else if(OS.indexOf("mac") >= 0)
//your code for MAC OS.
else if(OS.indexOf("sunos") >= 0)
//your code for Solaris OS
else if(OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 )
//your code for unix OS's

Step 2: use required commands to get the UUID of a system
What is a UUID?

A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems.

For windows

Runtime.exec("wmic csproduct get UUID");

The cmd command wmic csproduct get UUID returns the UUID of PC [windows]

For Linux
use this kernal command with Runtime.exec("YOUR COMMAND")

# cat /sys/class/dmi/id/product_uuid

To know more about Runtime.exec check this java.lang.Runtime.exec

java.lang.Runtime.exec : Through this, you supply the appropriate shell command for any underlying Environment, whether be MAC, Windows, Linux etc.

Any solution to get the list of smartcards inside OS X?

..Or someone would know a way to force the JVM from a Applet (simple method)?

We cannot really 'force' the user to do anything (not that we should), but by launching the applet using Java Web Start we can request particular versions of the JRE. Here's a rundown.

Java Web Start - Runtime Versioning

Java Web Start can be used to ensure that an application
gains a certain minimum version of the JRE
(Java Runtime Environment) that it requires to run.
Web start can also be used to ensure a specific
micro-version of the JRE
is available to an application, or that an
earlier major release
is used (e.g. using 1.3, on a system where 1.6 is installed).

Unless the system is correctly configured, the user might be
prompted for download.

Minimum Version

Java web start can be used to ensure a Java project is launched
with a particular minimum version of Java. For example, if the application
uses generics, but nothing beyond what is available in Java 1.5, the
JNLP deployment descriptor might include a section that says..

..
<resources>
<j2se version='1.5+'>
...
</resources>

Micro Version

Besides being able to specify a minimum Java Major version, the
deployer can also mandate a particular micro-version. An example
of where this can be handy, might be seen in changes to JRE's based
on new information about Daylight Savings Time (which can be changed
by regional governments at any time they see the need to change them).

..
<resources>
<j2se version='1.5.0_11'>
...
</resources>

Earlier Version

Web start has a handy feature in that it can allow us to
test applications against specific earlier Java versions.
For example, if the local build environment is based around 1.6,
but an application is supposedly 1.5+, it pays to test the
final product in a 1.5 JRE prior to deployment. Invoking a 1.5
JRE in the 1.6 environment can be as simple as.

..
<resources>
<j2se version='1.5'>
...
</resources>

Note the difference to the first example, which used '1.5+',
whereas this one uses '1.5' - to indicate that only a 1.5
JRE will do.

An alternative version..

..
<resources>
<j2se version='1.5*'>
...
</resources>

Prompt for Download

A problem commonly reported by people deploying applications
via web start, is that they are being prompted to download versions
of Java that are already locally installed.

Even if a specific Java
version is installed, it might not be flagged as being 'available'
for use by web start.
This can be easily fixed.

Open the Java Control Panel.

<img src="jcp-javaapplication.gif">

Select the Java tab and click the View
button of Java Application Runtime Settings.
You might see something like this.

<img src="jcp-javaruntimesettings.gif">

Note which ones are Enabled (right column). This PC is
set up to use
1.6.0,
1.5.0_11, or
1.5.0_08. Neither of the
1.5.0-beta or
1.5.0_01 micro versions is available.
That is purely by my choice - if I needed to test against these
very early 1.5 versions, I could simply enable them as needed.

Ensure any versions of interest are Enabled and the problem
should be fixed. Web start will be able to load that version of the
JRE and use it, without any prompt for download.

If you have versions installed that do not
appear
in the User list, click Find to
launch the JRE Finder to
search for them. The (Java 1.6) JRE Finder will
present a dialog with a message along these lines.

In order to launch applications, Java Web Start needs to know
the locations of installed Java Runtime Environments.

You can either select a known JRE, or select a directory in
the file system from which to search for JREs.

A thread
on the web start forum also produced the following comments
from Andy Herrick.

On Windows, the list of available JRE's is populated from
the registry which contains pointers to all the publicly
installed JRE's.
(It will not automatically include private JRE's, such as
those installed by a JDK install, where "install public JRE"
is not selected.).

On unix it will only, by default, contain
the JRE it came with and any installed by java web start or
that came with any previous version of java web start that
had previously been run.

He adds a further note on specifying a download source..

Using either:

<j2se version="1.5*" href="http://java.sun.com/products/autodl/j2se">

or

<j2se version="1.5" >

will get you any 1.5 version available on the system.

If you use the href attribute, you are asking for the particular update release, so..

<j2se version="1.5" href="http://java.sun.com/products/autodl/j2se">

..will only work with 1.5.0_00.



Related Topics



Leave a reply



Submit