The Java code calls the DOS ipconfig/all command to obtain the NIC details.

Source: Internet
Author: User
Package test; import Java. io. bufferedreader; import Java. io. ioexception; import Java. io. inputstreamreader;/*** @ author javaalpha * @ date 2011-12-14 * @ Version V 1.0 * Java Code Call the DOS ipconfig/all command to obtain the NIC details */public class ipconfig {/*** @ Param ARGs */public static void main (string [] ARGs) {// obtain the machine name string hostname = getlocalmachineinfo ("Host Name ............: "); system. out. println ("machine name:" + hostname); // obtain the NIC model string DESC = getlocalmachineinfo ("Description ...........: "); system. out. println ("Nic model:" + DESC); // obtain the MAC address string MAC = getlocalmachineinfo ("physi Cal address .........: "); system. out. println ("MAC address:" + Mac); // obtain the IP address string IP = getlocalmachineinfo ("ip address ............: "); system. out. println ("IP Address:" + IP); // obtain the subnet mask string subnetmask = getlocalmachineinfo ("subnet mask ...........: "); system. out. println ("subnet mask:" + subnetmask); // obtain the default gateway string DefaultGateway = getlocalmachineinfo ("Default Gateway .........: "); sys TEM. out. println ("machine name:" + DefaultGateway); // obtain the DNS Server String dnsservers = getlocalmachineinfo ("DNS servers ...........: "); system. out. println ("machine name:" + dnsservers);} static string getlocalmachineinfo (string Str) {string line = ""; int N; try {process PS = runtime.getruntime(cmd.exe C ("CMD/C ipconfig/all"); bufferedreader BR = new bufferedreader (New inputstreamreader (PS. getinputstream (); While (null! = (Line = Br. Readline () {If (line. indexof (STR )! =-1) {n = line. indexof (":"); line = line. substring (n + 2); break;} ps. waitfor ();} catch (ioexception e) {e. printstacktrace ();} catch (exception e) {e. printstacktrace () ;}return line ;}}

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.