Java Get computer parameters [Ipvsmac]

Source: Internet
Author: User
Tags microsoft teredo tunneling adapter

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  class systemutils {    //By intercepting the Cmd stream to get the configuration information of the computer (bad)     Public StaticList<string>Getcmdipconfiginfo() {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 }//Get computer information, including IP address and MAC address     Public Static void GetSystemInfo() {Try{InetAddress address = inetaddress.getlocalhost ();            NetworkInterface ni = networkinterface.getbyinetaddress (address); String hostName = Address.gethostname (). toString ();//Get the native computer nameProperties props = System.getproperties (); String osname = Props.getproperty ("Os.name"); String osversion = Props.getproperty ("Os.version");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 ("Native IP:"+ SIP); System.out.println ("native Mac:"+ SMAC); System.out.println ("native name:"+ HostName); System.out.println ("Operating system name:"+ Osname); System.out.println ("OS version:"+ osversion);            map<string, string> map = system.getenv (); System.out.println ("User name:"+ Map.get ("USERNAME"));//Get user nameSystem.out.println ("Computer name:"+ Map.get ("COMPUTERNAME"));//Get computer nameSystem.out.println ("Computer domain name:"+ Map.get ("UserDomain"));//Get computer domain name}Catch(Exception e)        {E.printstacktrace (); }    } Public Static void Main(string[] args)        {Getcmdipconfiginfo (); System.out.println ("=========================");    GetSystemInfo (); }}

Run results

Windows IP Configuration Host Name ............:sd-20150114Ohcz Primary Dns Suffix ...: Node Type .....: Hybrid IP Routing, .....Enabled. . . . . . . . : No WINS ProxyEnabled. . . . . . . . : nowireless LAN Adapter Wireless network connection: Connection-specific DNS Suffix. : Description ........... :802.11n USB Wireless LAN Card physical Address ..... . :xx- the- $-Geneva-b3-f9 DHCPEnabled. . . . . . . . . . . : No autoconfigurationEnabled. . . . : Yes link-local IPv6 Address .....: FE80::7927: -A:4c17:aeb2% the(Preferred) IPv4 the Address ..... :172.24. 187. 1(Preferred) Subnet Mask ........... :255.255. 0. 0   DefaultGateway ..... . : DHCPv6 IAID ........... :268470070DHCPv6 Client DUID ... :xx- on-xx- on-1C- --b7-2D-b4-b5-2F-ae-ae-da DNS Servers ........... : FEC0:0:0: FFFF::1%1FEC0:0:0: FFFF::2%1FEC0:0:0: FFFF::3%1NetBIOS over Tcpip ..... :EnabledEthernet Adapter Local Connection: Connection-specific DNS Suffix. : Description ........... : Realtek PCIe GBE Family Controller physical Address ..... . : d8-d3- --Ten-ca-9EDhcpEnabled. . . . . . . . . . . : No autoconfigurationEnabled. . . . : Yes IPv6 Address ..... :2001: -:1006:5072:3D15:FA6A:8397:1B02 (Preferred)TemporaryIPv6 Address ... :2001: -:1006:5072:3C02:dc92: theF6:1DA0 (Preferred) link-local IPv6 Address ...: fe80::3D15:FA6A:8397:1b02% A(Preferred) IPv4 the Address ..... :192.168. 0. the(Preferred) Subnet Mask ........... :255.255. 255. 0   DefaultGateway ..... . : FE80::223: theFF:FE1A: thea% A                                       192.168. 0. 1DNS Servers ........... :61.134. 1. 4                                       8.8. 8. 4NetBIOS over Tcpip ..... :EnabledEthernet Adapter VirtualBox host-only network:connection-specific DNS Suffix. : Description ........... : VirtualBox host-only Ethernet Adapter physical Address .... . : ,-xx- --xx-Ten-4B DHCPEnabled. . . . . . . . . . . : No autoconfigurationEnabled. . . . : Yes link-local IPv6 Address ....: fe80::c1e7:db1f:ce48:1Bbe% -(Preferred) IPv4 the Address ..... :192.168. the. 1(Preferred) Subnet Mask ........... :255.255. 255. 0   DefaultGateway ..... . : DHCPv6 IAID ........... :369623079DHCPv6 Client DUID ... :xx- on-xx- on-1C- --b7-2D-b4-b5-2F-ae-ae-da DNS Servers ........... : FEC0:0:0: FFFF::1%1FEC0:0:0: FFFF::2%1FEC0:0:0: FFFF::3%1NetBIOS over Tcpip ..... :EnabledTunnel adapter ISATAP.{7fc65ef3-4b94-4874-8f98-2611d93d4853}: Media State ........... : Media disconnected connection-specific DNS Suffix. : Description ........... : Microsoft ISATAP Adapter physical Address ..... . :xx-xx-xx-xx-xx-xx-xx-e0 DHCPEnabled. . . . . . . . . . . : No autoconfigurationEnabled. . . . : Yestunnel Adapter Local Connection *8: Media State ........... : Media disconnected connection-specific DNS Suffix. : Description ........... : Microsoft Teredo tunneling Adapter physical Address ..... . :xx-xx-xx-xx-xx-xx-xx-e0 DHCPEnabled. . . . . . . . . . . : No autoconfigurationEnabled. . . . : Yestunnel adapter ISATAP.{46B2F22B-8DC1-4604-AA54-A01C66B7C9A4}: Media State ........... : Media disconnected connection-specific DNS Suffix. : Description ........... : Microsoft ISATAP Adapter #2Physical Address ..... . :xx-xx-xx-xx-xx-xx-xx-e0 DHCPEnabled. . . . . . . . . . . : No autoconfigurationEnabled. . . . : Yestunnel adapter ISATAP.{db0446ad-4833-4b88-bce1-da18ecc8d756}: Media State ........... : Media disconnected connection-specific DNS Suffix. : Description ........... : Microsoft ISATAP Adapter #3Physical Address ..... . :xx-xx-xx-xx-xx-xx-xx-e0 DHCPEnabled. . . . . . . . . . . : No autoconfigurationEnabled. . . . : yes========================= Native IP:192.168. 0. theNative mac:d8-d3- --Ten-ca-9EMachine Name: sd-20150114Ohcz Operating system name: Windows7Operating system version:6.1User name: Administrator computer name: sd-20150114Ohcz Computer domain name: sd-20150114Ohcz

Java Get computer parameters [Ipvsmac]

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.