Java get computer IP, MAC, various versions

Source: Internet
Author: User

Java code get computer IP, MAC, various versions

 Packagecom.rapoo.middle.action;ImportJava.io.BufferedReader;ImportJava.io.InputStream;ImportJava.io.InputStreamReader;Importjava.net.InetAddress;ImportJava.net.NetworkInterface;Importjava.util.ArrayList;ImportJava.util.Formatter;Importjava.util.List;ImportJava.util.Locale;ImportJava.util.Map;Importjava.util.Properties;  Public classSystemutil {//Computer Configuration information is obtained by intercepting the Cmd stream (bad)     Public StaticList<string>getipaddress () {Process P=NULL; List<String> address =NewArraylist<string>(); Try{p=NewProcessbuilder ("ipconfig", "/all"). Start (); }Catch(Exception e) {returnaddress; } stringbuffer SB=NewStringBuffer (); //read process output valueInputStream InputStream =P.getinputstream (); BufferedReader BR=NewBufferedReader (NewInputStreamReader (InputStream)); String s= ""; Try{              while((S=br.readline ())! =NULL) {Sb.append (s+ "\ n"); }         }Catch(Exception e) {e.printstacktrace (); }finally{             Try{inputstream.close (); }Catch(Exception e) {e.printstacktrace ();         }} System.out.println (SB); returnaddress; }          Public Static voidGetipconfig () {Map<String,String> map =system.getenv (); System.out.println (Map.get ("USERNAME"));//Get user nameSystem.out.println (Map.get ("COMPUTERNAME"));//Get computer nameSystem.out.println (Map.get ("UserDomain"));//get computer domain name    }     //get the computer's IP address and MAC address     Public Static voidGetConfig () {Try{inetaddress Address=Inetaddress.getlocalhost (); NetworkInterface ni=networkinterface.getbyinetaddress (address); //ni.getinetaddresses (). Nextelement (). getaddress ();             byte[] Mac =ni.gethardwareaddress (); String SIP=address.gethostaddress (); String SMAC= ""; Formatter Formatter=NewFormatter ();  for(inti = 0; i < mac.length; i++) {SMAC= Formatter.format (Locale.getdefault (), "%02x%s", Mac[i], (i< mac.length-1)? "-" : ""). toString (); } System.out.println ("IP:" +SIP); System.out.println ("MAC:" +SMAC); }Catch(Exception e) {e.printstacktrace (); }     }     //get the computer's IP, name, operating system name, operating system version     Public Static voidConfig () {Try{inetaddress addr=Inetaddress.getlocalhost (); String IP=addr.gethostaddress (). toString ();//get the native IPString hostname=addr.gethostname (). toString ();//get the native computer nameSystem.out.println ("Native IP:" +ip+ "\ nthe native name:" +hostName); Properties Props=system.getproperties (); System.out.println ("Name of the operating system:" +props.getproperty ("Os.name")); System.out.println ("Version of the operating system:" +props.getproperty ("Os.version")); }Catch(Exception e) {e.printstacktrace (); }     }        //Java Environment     Public Static voidAll () {Properties props=system.getproperties (); System.out.println ("Runtime version of Java:" +props.getproperty ("Java.version"))); System.out.println ("Java Operating Environment Vendor:" +props.getproperty ("Java.vendor"))); System.out.println ("Java Vendor URL:" +props.getproperty ("Java.vendor.url"))); System.out.println ("Installation path for Java:" +props.getproperty ("Java.home"))); System.out.println ("Java version of the virtual machine specification:" +props.getproperty ("Java.vm.specification.version")); System.out.println ("Java specification Provider for virtual machines:" +props.getproperty ("Java.vm.specification.vendor")); System.out.println ("Java Virtual Machine Specification Name:" +props.getproperty ("Java.vm.specification.name"))); System.out.println ("Java Virtual Machine Implementation version:" +props.getproperty ("Java.vm.version"))); System.out.println ("Java Virtual machine Implementation provider:" +props.getproperty ("Java.vm.vendor")); System.out.println ("Java Virtual machine implementation name:" +props.getproperty ("Java.vm.name")); System.out.println ("Java Runtime Environment Specification version:" +props.getproperty ("Java.specification.version"))); System.out.println ("Java Runtime Environment Specification vendor:" +props.getproperty ("Java.specification.vender")); System.out.println ("Java Runtime Environment Specification name:" +props.getproperty ("Java.specification.name"))); System.out.println ("Java class format version number:" +props.getproperty ("Java.class.version"))); System.out.println ("Java classpath:" +props.getproperty ("Java.class.path"))); System.out.println ("List of paths searched when loading library:" +props.getproperty ("Java.library.path")); System.out.println ("Default temporary file path:" +props.getproperty ("Java.io.tmpdir"))); System.out.println ("Path to one or more extended directories:" +props.getproperty ("Java.ext.dirs")); System.out.println ("Name of the operating system:" +props.getproperty ("Os.name")); System.out.println ("Architecture of the Operating system:" +props.getproperty ("Os.arch"))); System.out.println ("Version of the operating system:" +props.getproperty ("Os.version")); System.out.println ("File delimiter:" +props.getproperty ("File.separator"));//in Unix system is "/" System.out.println ("Path delimiter:" +props.getproperty ("Path.separator"));//in Unix system is ":" System.out.println ("line delimiter:" +props.getproperty ("Line.separator"));//in the UNIX system is "/n" System.out.println ("User's account name:" +props.getproperty ("User.Name")); System.out.println ("User's home directory:" +props.getproperty ("User.home"))); System.out.println ("User's current working directory:" +props.getproperty ("User.dir"))); }      Public Static voidMain (string[] args) {Config ();//All ();    } }

Java get computer IP, MAC, various versions

Related Article

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.