Some methods for obtaining operating system information from Java collected on the Internet are summarized as follows:
1. String OS = system. getproperty ("OS. Name"). tolowercase ();
2,
1. Obtain the IP address of the local machine:
Java code
Private Static string getipaddress () throws unknownhostexception {
Inetaddress address = inetaddress. getlocalhost ();
Return address. gethostaddress ();
}
Private Static string getipaddress () throws unknownhostexception {
Inetaddress address = inetaddress. getlocalhost ();
Return address. gethostaddress ();
}
2. Obtain the NIC address
Java code
Public static string getmacaddress (){
String address = "";
String OS = system. getproperty ("OS. Name ");
String osuser = system. getproperty ("user. Name ");
If (OS! = NULL & OS. startswith ("Windows ")){
Try {
String command = "cmd.exe/C ipconfig/all ";
PROCESS p = runtime.getruntime(cmd.exe C (command );
Bufferedreader BR = new bufferedreader (New inputstreamreader (P. getinputstream ()));
String line;
While (line = Br. Readline ())! = NULL ){
If (line. indexof ("physical address")> 0 ){
Int Index = line. indexof (":");
Index + = 2;
Address = line. substring (INDEX );
Break;
}
}
BR. Close ();
Return address. Trim ();
}
Catch (ioexception e ){
}
}
Return address;
}
Public static string getmacaddress (){
String address = "";
String OS = system. getproperty ("OS. Name ");
String osuser = system. getproperty ("user. Name ");
If (OS! = NULL & OS. startswith ("Windows ")){
Try {
String command = "cmd.exe/C ipconfig/all ";
PROCESS p = runtime.getruntime(cmd.exe C (command );
Bufferedreader BR = new bufferedreader (New inputstreamreader (P. getinputstream ()));
String line;
While (line = Br. Readline ())! = NULL ){
If (line. indexof ("physical address")> 0 ){
Int Index = line. indexof (":");
Index + = 2;
Address = line. substring (INDEX );
Break;
}
}
BR. Close ();
Return address. Trim ();
}
Catch (ioexception e ){
}
}
Return address;
}
3. Obtain the operating system account
Java code
String osuser = system. getproperty ("user. Name ");
String osuser = system. getproperty ("user. Name ");
4. Obtain the OS version.
Java code
Import java. util. properties;
Properties props = system. getproperties (); // obtain the system property set
String osname = props. getproperty ("OS. Name"); // operating system name
String osarch = props. getproperty ("OS. Arch"); // Operating System Architecture
String osversion = props. getproperty ("OS. Version"); // operating system version
Import java. util. properties;
Properties props = system. getproperties (); // obtain the system property set
String osname = props. getproperty ("OS. Name"); // operating system name
String osarch = props. getproperty ("OS. Arch"); // Operating System Architecture
String osversion = props. getproperty ("OS. Version"); // operating system version
5. Obtain some common information
Java code
Public static string getproperty (string key)
Key-related value description
Java. Version Java Runtime Environment version
Java. Vendor Java Runtime Environment vendor
Java. Vendor. url URL of the Java vendor
Java. Home Java installation directory
Java. VM. Specification. Version Java Virtual Machine standard version
Java. VM. Specification. Vendor Java virtual machine specification vendor
Java. VM. Specification. Name Java virtual machine specification name
Java. VM. Version Java Virtual Machine implementation version
Java. VM. Vendor Java Virtual Machine implementation vendor
Java. VM. Name Java Virtual Machine implementation name
Java. Specification. Version Java Runtime Environment Standard version
Java. Specification. Vendor Java Runtime Environment specification vendor
Java. Specification. Name Java Runtime Environment Standard name
Java. Class. Version Java class format version number
Java. Class. Path Java class path
List of paths searched when the java. Library. Path library is loaded
Java. Io. tmpdir default temporary file path
Name of the JIT compiler to be used by Java. Compiler
Java. Ext. dirs: path of one or more extension Directories
OS. Name of the Operating System
OS. Arch Operating System Architecture
OS. Version
File. Separator file delimiter ("/" in UNIX)
Path. Separator path separator (":" in UNIX systems)
Line. Separator line separator ("/n" in UNIX ")
User. Name: Account name of the user
User. Home user's home directory
Current working directory of user. dir