Practical code-C # obtain the network adapter information and MAC address of the Local Machine

Source: Internet
Author: User

The system. net. networkinformation space provides access to network traffic data, network address information, and address change notifications of local computers. The namespace also contains the class that implements the Ping utility. You can use Ping and related classes to check whether a computer can be connected over the network. When I checked msdn, I accidentally turned to it and found it quite interesting. msdn also gave me a specific example. Now I can write it down, maybe it will be used later.

 1   Public   Static   Void  Shownetwork ()  2   {  3 Networkinterface [] networkinterface = 4   Networkinterface. getallnetworkinterfaces ();  5       Foreach (Networkinterface AdapterIn  Networkinterface)  6   {  7 Console. writeline ( "  Description ------------:  " + Adapter. Description );  8 Console. writeline ( "  Network Adapter Name:  " + Adapter. Name );  9 Console. writeline ( "  Interface Type --------:  " + Adapter. networkinterfacetype );  10 Console. writeline ( "  Status ------------:  " + Adapter. operationalstatus );  11 Physicaladdress address = Adapter. getphysicaladdress ();  12           Byte [] Bytes =Address. getaddressbytes ();  13 Console. Write ( "  Mac -------------:  "  );  14           For ( Int I = 0 ; I <bytes. length; I ++ )  15   {  16 Console. Write ( " {0}  " , Bytes [I]. tostring ( "  X2  "  ));  17               If (I! = Bytes. Length- 1  )  18   {  19 Console. Write ( "  -  " );  20   }  21   }  22   Console. writeline ();  23 Console. writeline ( "  ======================  "  );  24   Console. writeline ();  25   } 26 }
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.