Esempio n. 1
0
        /// <summary>
        /// Get IFTable
        /// </summary>
        /// <returns>MIB_IFTABLE Class</returns>
        private static MIB_IFTABLE GetAllIfTable()
        {
            //缓冲区大小
            uint dwSize = 0;

            //获取缓冲区大小
            uint ret = GetIfTable(null, ref dwSize, false);

            if (ret == 50)
            {
                //此函数仅支持于 win98/nt 系统
                return(null);
            }

            //定义,获取 MIB_IFTABLE 对象
            MIB_IFTABLE tbl = new MIB_IFTABLE((int)dwSize);

            ret = GetIfTable(tbl.ByteArray, ref dwSize, false);

            //如果不成功
            if (ret != 0)
            {
                return(null);
            }

            return(tbl);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取所有的网络信息
        /// </summary>
        /// <returns>NetInfo 网络信息范型</returns>
        public static List <NetInfo> GetAllNetInfo()
        {
            //定义范型
            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++)
                {
                    ninfos.Add(GetNetInfo(tbl.Table[i]));
                }
            }

            return(ninfos);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        /// <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);
        }