码迷,mamicode.com
首页 > 系统相关 > 详细

读网上MAC

时间:2016-05-17 22:41:02      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:

 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  

 

读网上MAC

标签:

原文地址:http://www.cnblogs.com/linhongquan/p/5503415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!