/// <summary> /// 获取指定物理地址的网络信息 /// </summary> /// <param name="MACAddress">物理地址</param> /// <returns>NetInfo 网络信息范型</returns> public static NetInfo GetNetInfoByMac(string MACAddress) { //定义,获取 MIB_IFTABLE 对象 MIB_IFTABLE tbl = GetAllIfTable(); //如果成功 if (tbl != null) { tbl.Deserialize(); for (int i = 0; i < tbl.Table.Length; i++) { NetInfo ninfo = GetNetInfo(tbl.Table[i]); if (string.Compare(MACAddress, ninfo.PhysAddr, true) == 0) { return(ninfo); } } } return(null); }
/// <summary> /// 获取指定类型的网络信息 /// </summary> /// <param name="nettype">网络类型</param> /// <returns>NetInfo 网络信息范型</returns> public static List <NetInfo> GetNetInfoByType(NetType nettype) { //定义范型 List <NetInfo> ninfos = new List <NetInfo>(); //定义,获取 MIB_IFTABLE 对象 MIB_IFTABLE tbl = GetAllIfTable(); //如果成功 if (tbl != null) { tbl.Deserialize(); for (int i = 0; i < tbl.Table.Length; i++) { NetInfo ninfo = GetNetInfo(tbl.Table[i]); if (ninfo.Type == nettype) { ninfos.Add(ninfo); } } } return(ninfos); }