Exemplo n.º 1
0
 public IPInformation(IPInformation second)
 {
     ip          = second.ip;
     ipIndex     = second.ipIndex;
     equipIndex  = second.equipIndex;
     equipName   = second.equipName;
     ipMask      = second.ipMask;
     ipGateWay   = second.ipGateWay;
     ipName      = second.ipName;
     isDefaultIP = second.isDefaultIP;
 }
Exemplo n.º 2
0
        public void GetIPandInfomationFromDatabase()
        {
            string        sql = "SELECT IP_Address, IP_EquipID, IP_Mask, IP_GateWay, IP_Name, IP_IsDefaultIP, Equip_Name FROM IPAddress INNER JOIN Equipments ON IP_EquipID = Equip_Index WHERE IP_EquipID = " + index;
            SqlDataReader dr  = App.DBHelper.returnReader(sql);

            if (dr.HasRows)
            {
                ipAndInfoList.Clear();
                while (dr.Read())
                {
                    IpAddress     ip        = new IpAddress(dr["IP_Address"].ToString());
                    IpAddress     mask      = new IpAddress(dr["IP_Mask"].ToString());
                    IpAddress     gateway   = new IpAddress(dr["IP_GateWay"].ToString());
                    bool          isDefault = bool.Parse(dr["IP_IsDefaultIP"].ToString());
                    IPInformation ipInfo    = new IPInformation(ip, index, dr["Equip_Name"].ToString(), mask, gateway, dr["IP_Name"].ToString(), isDefault);
                    ipAndInfoList.Add(ip, ipInfo);
                }
                dr.Close();
            }
        }
Exemplo n.º 3
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);
        }