Ejemplo n.º 1
0
        /// <summary>
        /// 获取设置此设备的Dictionary (Int,IFInfomation) ifIDandIFInfoList。
        /// </summary>
        /// <param name="errorMessage">输出错误信息</param>
        /// <returns>是否成功获取</returns>
        public bool GetIFIDandIFInfoList(out string errorMessage)
        {
            bool          isSuccess      = false;
            IpAddress     agentIP        = adminIPAddress == null ? ipFirstGet : adminIPAddress;
            List <string> strIFIndexList = SnmpHelper.GetSingleColumnListFromTable(agentIP, new Oid("1.3.6.1.2.1.2.2.1.1"), out errorMessage);

            if (strIFIndexList == null)
            {
                isSuccess = false;
                return(isSuccess);
            }
            else
            {
                VbCollection vbc;
                ifIDandIFinfoLIst.Clear();
                foreach (string strIFIndex in strIFIndexList)
                {
                    //获取ifDescr,ifAdminStatus,ifOperStatus
                    vbc = SnmpHelper.GetResultsFromOids(agentIP, new string[] { "1.3.6.1.2.1.2.2.1.2." + strIFIndex, "1.3.6.1.2.1.2.2.1.7." + strIFIndex, "1.3.6.1.2.1.2.2.1.8." + strIFIndex }, out errorMessage);
                    if (vbc == null)
                    {
                        isSuccess = false;
                        return(isSuccess);
                    }
                    //暂时没有做接口自定义名称,现在只从snmp中获取信息
                    string descr       = vbc[0].Value.ToString();
                    int    index       = Convert.ToInt32(strIFIndex);
                    bool   adminStatus = vbc[1].Value.ToString().Equals("1") ? true : false;
                    bool   operStatus  = vbc[2].Value.ToString().Equals("1") ? true : false;
                    ifIDandIFinfoLIst.Add(index, new IFInfomation(descr, "", index, adminStatus, operStatus));
                }
                isSuccess = true;
            }
            return(isSuccess);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取设置此设备的Dictionary (IpAddress,RouteInformation) ipAndRouteInfoList。
        /// </summary>
        /// <param name="errorMessage">输出错误信息</param>
        /// <returns>是否成功获取</returns>
        public bool GetIPAndRouteInfoList(out string errorMessage)
        {
            bool          isSuccess    = false;
            IpAddress     agentIP      = adminIPAddress == null ? ipFirstGet : adminIPAddress;
            List <string> strIPDstList = SnmpHelper.GetSingleColumnListFromTable(agentIP, new Oid("1.3.6.1.2.1.4.21.1.1"), out errorMessage);

            if (strIPDstList == null)
            {
                isSuccess = false;
                return(isSuccess);
            }
            else
            {
                VbCollection vbc;
                ipDstAndRouteInfoLIst.Clear();
                foreach (string strIPDst in strIPDstList)
                {
                    //获取ipRouteIfIndex,ipRouteNextHop,ipRouteType ,ipRouteProto ,ipRouteMask
                    vbc = SnmpHelper.GetResultsFromOids(agentIP, new string[] { "1.3.6.1.2.1.4.21.1.2." + strIPDst, "1.3.6.1.2.1.4.21.1.7." + strIPDst, "1.3.6.1.2.1.4.21.1.8." + strIPDst, "1.3.6.1.2.1.4.21.1.9." + strIPDst, "1.3.6.1.2.1.4.21.1.11." + strIPDst }, out errorMessage);
                    if (vbc == null)
                    {
                        isSuccess = false;
                        return(isSuccess);
                    }
                    //暂时没有做接口自定义名称,现在只从snmp中获取信息
                    IpAddress       ipDst       = new IpAddress(strIPDst);
                    int             ifindex     = Convert.ToInt32(vbc[0].Value.ToString());
                    IpAddress       ipNextHop   = new IpAddress(vbc[1].Value.ToString());
                    int             routeType   = Convert.ToInt32(vbc[2].Value.ToString());
                    int             routeProto  = Convert.ToInt32(vbc[3].Value.ToString());
                    IpAddress       ipRouteMask = new IpAddress(vbc[4].Value.ToString());
                    RouteInfomation routeInfo   = new RouteInfomation(ipDst, ipRouteMask, ipNextHop, ifindex, routeType, routeProto);
                    ipDstAndRouteInfoLIst.Add(ipDst, routeInfo);
                }
                isSuccess = true;
            }
            return(isSuccess);
        }
Ejemplo n.º 3
0
        public bool GetARPInfoListFrom(out string errorMessage)
        {
            bool          success    = false;
            List <string> index1List = new List <string>();
            List <string> index2List = new List <string>();

            index1List = SnmpHelper.GetSingleColumnListFromTable(AdminIPAddress, new Oid("1.3.6.1.2.1.4.22.1.1"), out errorMessage);
            index2List = SnmpHelper.GetSingleColumnListFromTable(AdminIPAddress, new Oid("1.3.6.1.2.1.4.22.1.3"), out errorMessage);
            if (index1List == null || index2List == null || index1List.Count != index2List.Count)
            {
                success = false;
                return(success);
            }
            else
            {
                VbCollection vbc;
                arpInfoList.Clear();
                for (int i = 0; i < index1List.Count; i++)
                {
                    vbc = SnmpHelper.GetResultsFromOids(AdminIPAddress, new string[] { "1.3.6.1.2.1.4.22.1.2." + index1List[i] + "." + index2List[i], "1.3.6.1.2.1.4.22.1.4." + index1List[i] + "." + index2List[i] }, out errorMessage);
                    if (vbc == null)
                    {
                        success = false;
                        return(success);
                    }
                    int       id        = Convert.ToInt32(index1List[i]);
                    IpAddress ip        = new IpAddress(index2List[i]);
                    string    mac       = vbc[0].Value.ToString();
                    int       mediaType = Convert.ToInt32(vbc[1].Value.ToString());
                    ARPInfo   arp       = new ARPInfo(this, id, ip, mac, mediaType);
                    arpInfoList.Add(arp);
                }
                success = true;
            }
            return(success);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取设置此设备的Dictionary (IpAddress,IPInformation) ipAndInfoList
        /// </summary>
        /// <param name="errorMessage">输出错误信息</param>
        /// <returns>是否成功获取</returns>
        public bool GetIPAndInfoListFromSNMP(out string errorMessage)
        {
            bool          isSuccess = false;
            IpAddress     agentIP   = adminIPAddress == null ? ipFirstGet : adminIPAddress;
            List <string> strIPList = SnmpHelper.GetSingleColumnListFromTable(agentIP, new Oid("1.3.6.1.2.1.4.20.1.1"), out errorMessage);

            if (strIPList == null)
            {
                isSuccess = false;
                return(isSuccess);
            }
            else
            {
                strIPList.Remove("127.0.0.1"); // 地址表中应该只有一个127.0.0.1吧,如果不是则需要修改
                VbCollection vbc;
                ipAndInfoList.Clear();
                IpAddress ip = null;
                foreach (string strip in strIPList)
                {
                    vbc = SnmpHelper.GetResultsFromOids(agentIP, new string[] { "1.3.6.1.2.1.4.20.1.2." + strip, "1.3.6.1.2.1.4.20.1.3." + strip }, out errorMessage);
                    if (vbc == null)
                    {
                        isSuccess = false;
                        return(isSuccess);
                    }
                    IpAddress mask, gateWay;
                    string    ipName;
                    int       ifIndex;
                    bool      isDefault = false;
                    ifIndex = Convert.ToInt32(vbc[0].Value.ToString());
                    mask    = new IpAddress(vbc[1].Value.ToString());
                    ip      = new IpAddress(strip);
                    IPInformation ipInfo;
                    //IpAddress _ip, int _equipID, string _equipName, IpAddress _mask, IpAddress _gateway, string _name, bool _isDefault
                    if (index > 0 && App.ipAndIPinfoList.ContainsKey(strip))
                    {  // 说明这个equip是在数据库中有记录的,那么这个IP应该也是有记录的
                        IPInformation tempIPInfo = App.ipAndIPinfoList[strip];
                        //mask = tempIPInfo.IpMask; 还是采用snmp采集到的信息,毕竟真实一些
                        gateWay = tempIPInfo.IpGateWay;
                        ipName  = tempIPInfo.IpName;
                        if (isDefault = tempIPInfo.IsDefaultIP)
                        {
                            adminIPAddress = ip;
                        }
                        ipInfo = new IPInformation(ip, index, name, mask, gateWay, ipName, isDefault);
                    }
                    else
                    {
                        ipInfo = new IPInformation(ip, index, name, mask, null, "", isDefault);
                    }
                    ipInfo.Equip   = this;
                    ipInfo.IfIndex = ifIndex;
                    ipAndInfoList.Add(ip, ipInfo);
                }
                isSuccess = true;
                if (ipAndInfoList.Count == 1 && ip != null)  //当设备只有一个ip的时候,直接设为管理地址
                {
                    this.adminIPAddress           = ip;
                    ipAndInfoList[ip].IsDefaultIP = true;
                }
            }
            return(isSuccess);
        }