示例#1
0
        //  Updates the NicInfo struct
        //  Uses WMI to extract information about network adapters
        public void UpdateNicInfo()
        {
            NicInfo n = new NicInfo();

            NicList.Clear();

            foreach (ManagementObject a in AdapterCollection)
            {
                if ((bool)a.GetPropertyValue("PhysicalAdapter"))
                {
                    // Get info from AdapterColection
                    n.DeviceID    = (string)a.GetPropertyValue("DeviceID");
                    n.Name        = (string)a.GetPropertyValue("NetConnectionID");
                    n.Description = (string)a.GetPropertyValue("Description");
                    n.NetEnabled  = (bool)a.GetPropertyValue("NetEnabled");

                    // Fetch one specific adapter configuration based on DeviceID
                    ManagementObject mo = new ManagementObject("Win32_NetworkAdapterConfiguration.Index=" + n.DeviceID);

                    // Get IP info from that configuration
                    n.DHCP       = (bool)mo.GetPropertyValue("DHCPEnabled");
                    n.IpAddress  = (string[])mo.GetPropertyValue("IPAddress");
                    n.SubnetMask = (string[])mo.GetPropertyValue("IPSubnet");
                    n.Gateway    = (string[])mo.GetPropertyValue("DefaultIPGateway");
                    n.DNS        = (string[])mo.GetPropertyValue("DNSServerSearchOrder");

                    NicList.Add(n);
                    mo.Dispose();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Gets Nic Information
        /// </summary>
        public virtual NicInfo GetNicInfo(byte device)
        {
            // BIOS only supports nic from 0-3 (logical 1-4).
            if ((device >= 0) && (device <= 4))
            {
                // Ipmi OEM Nic Info uses zero based indexing. Nic interfaces
                // logically use 1 based indexing.
                if (device != 0)
                {
                    device = (byte)(device - 1);
                }

                GetNicInfoResponse nicInfo = (GetNicInfoResponse)this.IpmiSendReceive(
                    new GetNicInfoRequest(device), typeof(GetNicInfoResponse));

                NicInfo response = new NicInfo(nicInfo.CompletionCode);
                response.DeviceId = (int)(device + 1); // add 1 for Nic Number.

                // if success attempt to parse the mac address
                if (nicInfo.CompletionCode == 0)
                {
                    response.SetParamaters(nicInfo.HardwareAddress);
                }

                return(response);
            }
            else
            {
                // index out of range.
                return(new NicInfo(0xC9));
            }
        }
        private void lblAutoAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                SSHConnectionDetails sshConnection = sshConnectionDetails.Clone();
                sshConnection.ComputerName     = ApplyConfigVarsOnField(sshConnection.ComputerName);
                sshConnection.UserName         = ApplyConfigVarsOnField(sshConnection.UserName);
                sshConnection.Password         = ApplyConfigVarsOnField(sshConnection.Password);
                sshConnection.PrivateKeyFile   = ApplyConfigVarsOnField(sshConnection.PrivateKeyFile);
                sshConnection.PassPhrase       = ApplyConfigVarsOnField(sshConnection.PassPhrase);
                sshConnection.ConnectionName   = ApplyConfigVarsOnField(sshConnection.ConnectionName);
                sshConnection.ConnectionString = ApplyConfigVarsOnField(sshConnection.ConnectionString);

                if (lvwNICs.Items.Count > 0 && (MessageBox.Show("Clear all existing entries?", "Clear", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No))
                {
                    return;
                }
                else
                {
                    lvwNICs.Items.Clear();
                    lvwNICs.Items.Add(new ListViewItem("Querying " + sshConnection.ComputerName + "..."));
                    Application.DoEvents();
                }

                Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection(sshConnection);
                if (sshClient.IsConnected)
                {
                    lvwNICs.Items.Clear();
                    foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient))
                    {
                        NIXNICSubEntry dsse = new NIXNICSubEntry()
                        {
                            NICName = di.Name, WarningValueKB = (long)warningNumericUpDown.Value, ErrorValueKB = (long)errorNumericUpDown.Value
                        };
                        ListViewItem lvi = new ListViewItem()
                        {
                            Text = dsse.NICName
                        };
                        lvi.SubItems.Add(dsse.WarningValueKB.ToString());
                        lvi.SubItems.Add(dsse.ErrorValueKB.ToString());
                        lvi.Tag = dsse;
                        lvwNICs.Items.Add(lvi);
                    }
                }
                else
                {
                    lvwNICs.Items.Clear();
                    MessageBox.Show("Could not connect to computer!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
示例#4
0
 public ServerNicInfo(NicInfo nic)
 {
     this.BusNumber        = nic.BusNumber;
     this.DeviceNumber     = nic.DeviceNumber;
     this.FriendlyName     = nic.FriendlyName;
     this.Index            = nic.Index;
     this.IPAddresses      = nic.IPs;
     this.PNPInstanceId    = nic.PNPInstanceId;
     this.TcpIpServiceUuid = nic.TcpIpServiceUuid;
     this.VirtualNetwork   = nic.VirtualNetwork;
 }
示例#5
0
        public List <NICState> GetNICInfos()
        {
            List <NICState> nicEntries = new List <NICState>();

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();

            //First see if ANY subentry is for all
            bool addAll = (from LinuxNICSubEntry d in SubItems
                           where d.NICName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                LinuxNICSubEntry alertDef = (from LinuxNICSubEntry d in SubItems
                                             where d.NICName == "*"
                                             select d).FirstOrDefault();
                foreach (Linux.NicInfo ni in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    NICState nis = new NICState()
                    {
                        NICInfo = ni, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    nicEntries.Add(nis);
                }
            }
            else
            {
                foreach (Linux.NicInfo di in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    LinuxNICSubEntry alertDef = (from LinuxNICSubEntry d in SubItems
                                                 where d.NICName.ToLower() == di.Name.ToLower()
                                                 select d).FirstOrDefault();

                    if (alertDef != null)
                    {
                        if (!nicEntries.Any(f => f.NICInfo.Name.ToLower() == di.Name.ToLower()))
                        {
                            NICState dis = new NICState()
                            {
                                NICInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                            };
                            nicEntries.Add(dis);
                        }
                    }
                }
                SSHConnection.CloseConnection();
            }
            return(nicEntries);
        }
示例#6
0
        public static void Run()
        {
            //This class contains network info

            while(Nagme.Globals.programRunning){

                ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_NetworkAdapter WHERE Manufacturer != 'Microsoft' AND NOT PNPDeviceID LIKE 'ROOT\\%'");
                ManagementObjectCollection objCol = searcher.Get();

                List<NicInfo> currNic = new List<NicInfo>();

                foreach (ManagementObject mgtObject in objCol)
                {

                    NicInfo tmpNic = new NicInfo();

                    //PropertyData pd = mgtObject.Properties;
                    foreach (PropertyData pd in mgtObject.Properties)
                    {

                        String keyName = pd.Name;

                        if (keyName == "NetConnectionID")
                        {

                            String interfaceName = pd.Value.ToString();
                            Console.WriteLine("Interface: " + interfaceName);
                            tmpNic.InterfaceID = pd.Value.ToString();

                        }

                        else if (keyName == "Description")
                        {
                            String interfaceDescription = pd.Value.ToString();
                            Console.WriteLine("Description: " + interfaceDescription);
                            tmpNic.Description = pd.Value.ToString();
                        }
                        else if (keyName == "AdapterType")
                        {
                            if (pd.Value != null)
                            {
                                String adapterType = pd.Value.ToString();
                                Console.WriteLine("Type: " + adapterType);
                                tmpNic.Type = pd.Value.ToString();
                            }

                        }
                        else if (keyName == "Index")
                        {
                            UInt32 interfaceIndex = (UInt32)pd.Value;
                            Console.WriteLine("Interface Index: " + (int)interfaceIndex);
                        }
                        else if (keyName == "MACAddress")
                        {
                            if (pd.Value != null)
                            {
                                String macAddress = pd.Value.ToString();
                                Console.WriteLine("Mac Address: " + macAddress);
                                tmpNic.MacAddress = pd.Value.ToString();
                            }
                        }
                        else if (keyName == "Manufacturer")
                        {
                            String manufacturer = pd.Value.ToString();
                            Console.WriteLine("Manufacturer: " + manufacturer);
                            tmpNic.Manufacturer = pd.Value.ToString();
                        }
                        else if (keyName == "NetConnectionStatus")
                        {
                            UInt16 connectionStatus = (UInt16)pd.Value;
                            Console.WriteLine("Status: " + (int)connectionStatus);
                            tmpNic.Status = (int)connectionStatus;
                        }
                        else if (keyName == "NetEnabled")
                        {
                            bool enabled = (bool)pd.Value;
                            Console.WriteLine("Enabled: " + enabled);
                            tmpNic.Enabled = (bool)pd.Value;
                        }

                    }

                    currNic.Add(tmpNic);

                }

                INagMe register = (INagMe)XmlRpcProxyGen.Create(typeof(INagMe));
                register.Url = Nagme.Globals.xmlrpcAddress();

                if(register.updateNic(currNic.ToArray(), Nagme.Globals.DeviceID(), Nagme.Globals.DevicePassword())){
                    Console.WriteLine("Updated Nic");
                }else{
                    Console.WriteLine("Failed Updating Nic");
                }
                Console.WriteLine("");

                System.Threading.Thread.Sleep (60000);

            }
        }
示例#7
0
文件: NIXNIC.cs 项目: utobe/QuickMon
        public override MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent     = Description,
                State        = CollectorState.None,
                CurrentValue = ""
            };

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();

            #region Get Disk infos and states
            List <NICInfoState> nicEntries = new List <NICInfoState>();
            //First see if ANY subentry is for all
            bool addAll = (from NIXNICSubEntry d in SubItems
                           where d.NICName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                NIXNICSubEntry alertDef = (from NIXNICSubEntry d in SubItems
                                           where d.NICName == "*"
                                           select d).FirstOrDefault();
                alertDef.PrimaryUIValue = false;
                foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    NICInfoState dis = new NICInfoState()
                    {
                        NICInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    nicEntries.Add(dis);
                }
            }
            else
            {
                foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    NIXNICSubEntry alertDef = (from NIXNICSubEntry d in SubItems
                                               where d.NICName.ToLower() == di.Name.ToLower()
                                               select d).FirstOrDefault();

                    if (alertDef != null)
                    {
                        if (!nicEntries.Any(f => f.NICInfo.Name.ToLower() == di.Name.ToLower()))
                        {
                            NICInfoState dis = new NICInfoState()
                            {
                                NICInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                            };
                            nicEntries.Add(dis);
                        }
                    }
                }
            }
            #endregion

            SSHConnection.CloseConnection();

            int    errors   = 0;
            int    warnings = 0;
            int    success  = 0;
            double average  = 0;
            foreach (NICInfoState dis in nicEntries)
            {
                average += dis.NICInfo.RTxBytesPerSec;
                if (dis.NICInfo.RTxBytesPerSec >= dis.AlertDefinition.ErrorValueKB * 1024)
                {
                    dis.State = CollectorState.Error;
                }
                else if (dis.NICInfo.RTxBytesPerSec >= dis.AlertDefinition.WarningValueKB * 1024)
                {
                    dis.State = CollectorState.Warning;
                }
                else
                {
                    dis.State = CollectorState.Good;
                    success++;
                }
                if (dis.AlertDefinition.PrimaryUIValue)
                {
                    currentState.CurrentValue     = dis.NICInfo.RTxBytesPerSec.ToString("0");
                    currentState.CurrentValueUnit = "Bytes/Sec";
                }

                MonitorState diskIOState = new MonitorState()
                {
                    ForAgent         = dis.NICInfo.Name,
                    State            = dis.State,
                    CurrentValue     = dis.NICInfo.RTxBytesPerSec.ToString("0"),
                    CurrentValueUnit = "Bytes/Sec",
                    PrimaryUIValue   = dis.AlertDefinition.PrimaryUIValue
                };
                currentState.ChildStates.Add(diskIOState);
            }
            if (errors > 0 && warnings == 0 && success == 0) // any errors
            {
                currentState.State = CollectorState.Error;
            }
            else if (errors > 0 || warnings > 0) //any warnings
            {
                currentState.State = CollectorState.Warning;
            }
            else
            {
                currentState.State = CollectorState.Good;
            }

            if (currentState.CurrentValue.ToString() == "" && currentState.ChildStates.Count > 0)
            {
                currentState.CurrentValue     = (average / currentState.ChildStates.Count).ToString("0.0");
                currentState.CurrentValueUnit = "Bytes/Sec (avg)";
            }

            return(currentState);
        }