首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么让获取的多网卡的信息(IP,mac,连接状态等)

2012-02-10 
如何让获取的多网卡的信息(IP,mac,连接状态等)如何让获取的多网卡的信息(IP,mac,连接状态等)[解决办法]ipc

如何让获取的多网卡的信息(IP,mac,连接状态等)
如何让获取的多网卡的信息(IP,mac,连接状态等)

[解决办法]
ipconfig /all > c:\a.txt

连接状态:
Ethernet adapter 本地连接 5:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : IPSec VPN Virtual Adapter
Physical Address. . . . . . . . . : 08-00-58-00-00-05
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 10.254.0.3
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :

未连接状态:
Ethernet adapter 本地连接 5:

Media State . . . . . . . . . . . : Media disconnected
Description . . . . . . . . . . . : IPSec VPN Virtual Adapter
Physical Address. . . . . . . . . : 08-00-58-00-00-05

分析两个状态就能得到IP、MAC、状态等信息

[解决办法]
做一个DOS程序。。IPCONFIG /all 然后就可以获取了。。。
[解决办法]
状态Media State . . . . . . . . . . . : Media disconnected
[解决办法]

C# code
本地IP地址using System.Net;IPHostEntry ipHost = Dns.Resolve(Dns.GetHostName()); ;IPAddress ipaddress = ipHost.AddressList[0];string ips = ipaddress.ToString();MAC地址 string strMac = ""; NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();            foreach (NetworkInterface ni in interfaces)            {                if (ni.OperationalStatus == OperationalStatus.Up)                {                    strMac += ni.GetPhysicalAddress().ToString() + "|";//MAC地址                }            }ni.OperationalStatus.ToString();//网络连接状态
[解决办法]
C# code
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration  where IPEnabled='True' and MACAddress = '" + MACAddress + "'");                  ManagementObjectCollection queryCollection = query.Get();                  foreach (ManagementObject mo in queryCollection)                  {                      if ((bool)mo["IPEnabled"] == true)                      {                          if (mo["IPAddress"] != null)                              strIP = ((string[])mo["IPAddress"])[0];                      }                      else                      {                          strIP = "0.0.0.0";                      }                  } 

热点排行