1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Management; 10 namespace WinNIC 11 { 12 public partial class WinNIC : Form 13 { 14 ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration"); 15 public WinNIC() 16 { 17 InitializeComponent(); 18 ManagementObjectCollection MOC = MC.GetInstances(); 19 foreach( ManagementObject MO in MOC ) 20 { 21 if( ( bool ) MO[ "IPEnabled" ] == true ) 22 { 23 textBox_MAC.Text = MO.Properties[ "MACAddress" ].Value.ToString(); 24 } 25 try 26 { 27 textBox_IP.Text = ( MO[ "IPAddress" ] as string[] ).GetValue( 0 ).ToString(); 28 textBox_SubNet.Text = ( MO[ "IPSubnet" ] as string[] ).GetValue( 0 ).ToString(); 29 textBox_NetGate.Text = ( MO[ "DefaultIPGateway" ] as string[] ).GetValue( 0 ).ToString(); 30 } 31 catch(SystemException /*e*/) 32 { 33 //MessageBox.Show(e.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error); 34 } 35 } 36 this.Text += " (Make:林宏权 2009/04/07)"; 37 } 38 } 39 } 40
时间: 2024-10-17 04:39:22