Java gets information about the current operating system

Source: Internet
Author: User

Java gets information about the current operating system Javaos virtual machine Unixext

Some of the ways in which Java obtains operating system information from the Internet are summarized below:

1 Get the IP address of this machine:

Java code
    1. Private static String getipaddress () throws unknownhostexception {
    2. InetAddress address = Inetaddress.getlocalhost ();
    3. return address.gethostaddress ();
    4. }

2 getting the NIC address

Java code
  1. Public static String getmacaddress () {
  2. String address = "";
  3. String OS = System.getproperty ("Os.name");
  4. String Osuser=system.getproperty ("User.Name");
  5. if (os! = null && os.startswith ("Windows")) {
  6. try {
  7. String command = "cmd.exe/c ipconfig/all";
  8. Process p = runtime.getruntime (). exec (command);
  9. BufferedReader br =new BufferedReader (new InputStreamReader (P.getinputstream ()));
  10. String Line;
  11. While (line = Br.readline ()) = null) {
  12. if (Line.indexof ("Physical Address") > 0) {
  13. int index = Line.indexof (":");
  14. Index + = 2;
  15. Address = line.substring (index);
  16. Break ;
  17. }
  18. }
  19. Br.close ();
  20. return Address.trim ();
  21. }
  22. catch (IOException e) {
  23. }
  24. }
  25. return address;
  26. }

3 Getting an operating system account

Java code
    1. String Osuser=system.getproperty ("User.Name");

4 getting the operating system version

Java code
  1. 1. Import java.util.Properties;
  2. 2.
  3. 3. Properties props=system.getproperties (); //Get system attribute set
  4. 4. String osname = Props.getproperty ("Os.name"); //operating system name
  5. 5. String Osarch = Props.getproperty ("Os.arch"); //Operating system Architecture
  6. 6. String osVersion = Props.getproperty ("os.version"); //Operating system version

5 Some commonly used information to get

Java code
  1. Public static string GetProperty (String key)
  2. Description of key correlation value
  3. Java.version Java Runtime Environment version
  4. Java.vendor Java Runtime Environment Vendor
  5. Java.vendor.url Java Vendor's URL
  6. Java.home Java installation directory
  7. Java.vm.specification.version Java Virtual Machine specification version
  8. Java.vm.specification.vendor Java Virtual Machine specification Provider
  9. Java.vm.specification.name Java Virtual Machine Specification Name
  10. Java.vm.version Java Virtual Machine implementation version
  11. Java.vm.vendor Java virtual Machine implementation Provider
  12. Java.vm.name Java virtual Machine implementation name
  13. Java.specification.version Java Runtime Environment specification version
  14. Java.specification.vendor Java Runtime Environment specification vendor
  15. Java.specification.name Java Runtime Environment Specification name
  16. Java. class.version Java Class format version number
  17. Java. Class.path Java classpath
  18. Java.library.path List of paths to search when loading libraries
  19. Java.io.tmpdir the default temporary file path
  20. Java.compiler the name of the JIT compiler to use
  21. Java.ext.dirs path to one or more extended directories
  22. Os.name name of the operating system
  23. Architecture of the Os.arch operating system
  24. Os.version version of the operating system
  25. File.separator file Delimiter ("/" in UNIX system)
  26. Path.separator path Delimiter (":" In UNIX system)
  27. Line.separator line Delimiter ("/n" in UNIX systems)
  28. User.Name User's account name
  29. User.home User's home directory
  30. User.dir User's current working directory

Java gets information about the current operating system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.