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 }