Ejemplo n.º 1
0
    protected void lbAddDevice_Click(object sender, EventArgs e)
    {
        string     ip = tbIPAddress.Text.Trim();
        Device     d  = DataProvider.Devices.FirstOrDefault(i => i.IpAddress == ip);
        FinalAgent fa = new FinalAgent(ip);

        SwitchInfo             = fa.GetBasicInformation();
        InterfaceInfo          = fa.GetInterfaceInformation();
        pnlAfterAdd.Visible    = true;
        ddlBuilding.DataSource = DataProvider.Buildings.ToList();
        ddlBuilding.DataBind();
        if (d == default(Device))
        {
            SwitchInfo.DeviceKey = CreateDeviceKey();
            ddlBuilding.Items.Insert(0, new ListItem()
            {
                Value = "-1", Text = "Please Select"
            });
            ddlBuilding.SelectedIndex = 0;
            pnlDeviceNotExist.Visible = true;
            pnlDeviceExist.Visible    = false;
        }
        else
        {
            SwitchBasicInformation sb = new SwitchBasicInformation()
            {
                DeviceKey = d.DeviceKey, DeviceType = d.DeviceType.DeviceTypeName, HostName = d.HostName, IPAddress = ip
            };
            //if (SwitchInfo.Equals(sb)) { string status = "değisiklik var"; }
            SwitchInfo.DeviceKey      = d.DeviceKey;
            ddlBuilding.SelectedValue = d.BuildingId.ToString();
            List <BasicInterfaceInformation> listBif = new List <BasicInterfaceInformation>();
            d.InterfaceInformations.ToList().ForEach(i => listBif.Add(new BasicInterfaceInformation()
            {
                IfCdpExist    = i.HasCdpInfo,
                IfConnected   = i.IsConnected,
                IfDescription = i.InterfaceName,
                IfIndex       = i.InterfaceIndex,
                IfNumber      = i.PortNumber,
                IfStat        = i.IsOpen
            }));
            foreach (BasicInterfaceInformation item in InterfaceInfo)
            {
                BasicInterfaceInformation bif = listBif.FirstOrDefault(i => i.IfIndex == item.IfIndex);
                if (bif == default(BasicInterfaceInformation) ||
                    item.IfCdpExist != bif.IfCdpExist ||
                    item.IfConnected != bif.IfConnected ||
                    item.IfDescription != bif.IfDescription ||
                    item.IfIndex != bif.IfIndex ||
                    item.IfNumber != bif.IfNumber ||
                    item.IfStat != bif.IfStat)
                {
                    item.IsUpdated = true;
                }
            }
            pnlDeviceNotExist.Visible = false;
            pnlDeviceExist.Visible    = true;
        }
        tbHostName.Text   = SwitchInfo.HostName;
        tbDeviceKey.Text  = SwitchInfo.DeviceKey;
        tbDeviceType.Text = SwitchInfo.DeviceType;
        QRCodeGenerate(SwitchInfo.DeviceKey);
        rpInterfaces.DataSource = InterfaceInfo;
        rpInterfaces.DataBind();
    }
Ejemplo n.º 2
0
    private void FindMacAlghrotihm()
    {
        List <JsonContent>          ipsWalkedJson = new List <JsonContent>();
        Dictionary <string, string> ipsWalked     = new Dictionary <string, string>();
        bool   cont = true;
        string ip   = ddlDevice.SelectedValue;
        string mac  = tbMacAddress.Text.Trim();
        string oid  = "1.3.6.1.2.1.17.4.3.1.2";

        foreach (string item in mac.Split(':'))
        {
            oid += "." + Int64.Parse(item, System.Globalization.NumberStyles.HexNumber);
        }
        while (cont)
        {
            Device      device      = DataProvider.Devices.FirstOrDefault(i => i.IpAddress == ip);
            JsonContent jsonContent = new JsonContent()
            {
                IpAddress         = ip,
                HostName          = device.HostName,
                FastEthernetCount = device.InterfaceInformations.Where(i => i.InterfaceName.StartsWith("Fa")).Count(),
                GigabitCount      = device.InterfaceInformations.Where(i => i.InterfaceName.StartsWith("Gi")).Count(),
                FaConnected       = device.InterfaceInformations.Where(i => i.InterfaceName.StartsWith("Fa") && i.IsConnected).Select(i => Convert.ToInt32(i.PortNumber.Replace("/", ""))).ToList(),
                GiConnected       = device.InterfaceInformations.Where(i => i.InterfaceName.StartsWith("Gi") && i.IsConnected).Select(i => Convert.ToInt32(i.PortNumber.Replace("/", ""))).ToList(),
                FaConnections     = new List <int>(),
                GiConnections     = new List <int>(),
                Building          = device.Building.BuildingName
            };
            //ipsWalked.Add(ip, "Not found in this device");
            FinalAgent fa          = new FinalAgent(ip);
            object     macBridgeNo = null;
            List <ITUBIDB.Net.Management.MIBS.SnmpMIB2.Interface> vlanStatic = fa.VlanList;
            foreach (var item in vlanStatic)
            {
                if (item.IsAdminUp())
                {
                    fa.ReconnectWithVlan(item.ifIndex.ToString());
                }
                macBridgeNo = fa.Get(oid);
                if (macBridgeNo != null)
                {
                    break;
                }
            }
            if (macBridgeNo != null)
            {
                object macIfIndexNo            = fa.Get("1.3.6.1.2.1.17.1.4.1.2." + macBridgeNo);
                object macIfDescr              = fa.Get("1.3.6.1.2.1.31.1.1.1.1." + macIfIndexNo);
                BasicInterfaceInformation intf = fa.GetInterfaceInformation().FirstOrDefault(i => i.IfIndex == Convert.ToInt32(macIfIndexNo.ToString()));
                if (intf.IfDescription.Contains("Fa"))
                {
                    jsonContent.FaConnections.Add(Convert.ToInt32(intf.IfDescription.Last().ToString()));
                }
                else
                {
                    jsonContent.GiConnections.Add(Convert.ToInt32(intf.IfDescription.Last().ToString()));
                }
                ipsWalkedJson.Add(jsonContent);
                //ipsWalked[ip] = "Found on : " + intf.IfDescription;
                if (intf.IfCdpExist)
                {
                    ip = fa.GetCdpList().FirstOrDefault(i => i.cdpIfIndex == intf.IfIndex).cdpAddress;
                }
                if (ipsWalkedJson.Where(i => i.IpAddress == ip).Count() > 0 || !DataProvider.Devices.Any(i => i.IpAddress == ip))
                {
                    cont = false;
                }
            }
            else
            {
                ipsWalkedJson.Add(jsonContent);
                cont = false;
            }
        }
        rp.DataSource = ipsWalkedJson.Select(i => i.ToString()).ToArray();
        rp.DataBind();
    }
Ejemplo n.º 3
0
    private void BindPage()
    {
        string key = Request.QueryString["key"];
        //string ip = Request.QueryString["ip"];
        Device d = DataProvider.Devices.FirstOrDefault(i => i.DeviceKey == key);

        if (d != default(Device))
        {
            FinalAgent fa = new FinalAgent(d.IpAddress);
            SwitchInfo             = fa.GetBasicInformation();
            InterfaceInfo          = fa.GetInterfaceInformation();
            ddlBuilding.DataSource = DataProvider.Buildings.ToList();
            ddlBuilding.DataBind();
            SwitchBasicInformation sb = new SwitchBasicInformation()
            {
                DeviceKey = d.DeviceKey, DeviceType = d.DeviceType.DeviceTypeName, HostName = d.HostName, IPAddress = d.IpAddress
            };
            //if (SwitchInfo.Equals(sb)) { string status = "değisiklik var"; }
            SwitchInfo.DeviceKey      = d.DeviceKey;
            ddlBuilding.SelectedValue = d.BuildingId.ToString();
            List <BasicInterfaceInformation> listBif = new List <BasicInterfaceInformation>();
            d.InterfaceInformations.ToList().ForEach(i => listBif.Add(new BasicInterfaceInformation()
            {
                IfCdpExist    = i.HasCdpInfo,
                IfConnected   = i.IsConnected,
                IfDescription = i.InterfaceName,
                IfIndex       = i.InterfaceIndex,
                IfNumber      = i.PortNumber,
                IfStat        = i.IsOpen
            }));
            foreach (BasicInterfaceInformation item in InterfaceInfo)
            {
                BasicInterfaceInformation bif = listBif.FirstOrDefault(i => i.IfIndex == item.IfIndex);
                if (bif == default(BasicInterfaceInformation) ||
                    item.IfCdpExist != bif.IfCdpExist ||
                    item.IfConnected != bif.IfConnected ||
                    item.IfDescription != bif.IfDescription ||
                    item.IfIndex != bif.IfIndex ||
                    item.IfNumber != bif.IfNumber ||
                    item.IfStat != bif.IfStat)
                {
                    item.IsUpdated = true;
                }
            }
            pnlDeviceExist.Visible = true;
            #region CdpBind
            Cdp            cdp       = new Cdp(fa.Agent);
            CdpResultSet   cdpResult = cdp.GetCdpList();
            List <CdpItem> cdpLi     = cdpResult.Values.SelectMany(i => i.Values.ToList()).ToList();
            rpCdp.DataSource = cdpLi;
            rpCdp.DataBind();
            foreach (RepeaterItem item in rpCdp.Items)
            {
                Label       lblAlias   = item.FindControl("lblCdpConnectedPort") as Label;
                HiddenField hdnIfIndex = item.FindControl("hdnCdpIfIndex") as HiddenField;
                lblAlias.Text = Convert.ToString(fa.Get(String.Concat("1.3.6.1.2.1.2.2.1.2.", hdnIfIndex.Value))).Replace("FastEthernet", "Fa ").Replace("GigabitEthernet", "Gi ");
            }
            #endregion
        }
        else
        {
            throw new Exception("Device not found");
        }
        tbHostName.Text   = SwitchInfo.HostName;
        tbDeviceKey.Text  = SwitchInfo.DeviceKey;
        tbDeviceType.Text = SwitchInfo.DeviceType;
        QRCodeGenerate(SwitchInfo.DeviceKey);
        rpInterfaces.DataSource = InterfaceInfo;
        rpInterfaces.DataBind();
    }