Ejemplo n.º 1
0
        public List <MacAddressDTOResponse> GetMacAddressInfo()
        {
            List <MacAddressDTOResponse> macAddresses = new List <MacAddressDTOResponse>();

            try
            {
                SelectQuery query = new SelectQuery(
                    @"select MACAddress 
					  from Win32_NetworkAdapter 
					  where MACAddress<>null"
                    );
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

                foreach (ManagementObject obj in searcher.Get())
                {
                    string mac = GetValueAsString(obj, "MACAddress");
                    if (Blacklists.IsMacInBlacklist(mac))
                    {
                        continue;
                    }

                    MacAddressDTOResponse macAddress = new MacAddressDTOResponse();
                    macAddress.Mac = mac;

                    macAddresses.Add(macAddress);
                }
            }
            catch (ManagementException e)
            {
                Logger.Instance.LogError(e.ToString());
            }

            return(macAddresses);
        }
Ejemplo n.º 2
0
        public List <EthernetDTOResponse> GetEthernetInfo()
        {
            List <EthernetDTOResponse> ethetnets = new List <EthernetDTOResponse>();

            try
            {
                SelectQuery query = new SelectQuery(
                    @"select Name,  MACAddress, Speed, Index 
					  from Win32_NetworkAdapter 
					  where MACAddress<>null"
                    );
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

                foreach (ManagementObject obj in searcher.Get())
                {
                    string mac = GetValueAsString(obj, "MACAddress");
                    if (Blacklists.IsMacInBlacklist(mac))
                    {
                        continue;
                    }

                    EthernetDTOResponse eth = new EthernetDTOResponse();
                    eth.Label = GetValueAsString(obj, "Name");
                    eth.Mac   = GetValueAsString(obj, "MACAddress");
                    eth.Speed = GetValueAsString(obj, "Speed");

                    try
                    {
                        SelectQuery queryAdapterConf = new SelectQuery(
                            @"select IPAddress,  IPSubnet 
							  from Win32_NetworkAdapterConfiguration 
							  where Index='"                             + GetValueAsString(obj, "Index") + "' and IPEnabled=True"
                            );
                        ManagementObjectSearcher adapterConfSearcher = new ManagementObjectSearcher(queryAdapterConf);

                        foreach (ManagementObject adapterConf in adapterConfSearcher.Get())
                        {
                            try
                            {
                                eth.IPAddress = ((string[])adapterConf["IPAddress"])[0];
                                eth.IPSubnet  = ((string[])adapterConf["IPSubnet"])[0];

                                ethetnets.Add(eth);
                            }
                            catch (ManagementException e)
                            {
                                Logger.Instance.LogError(e.ToString());
                            }
                            catch (Exception e)
                            {
                                Logger.Instance.LogError(e.ToString());
                            }

                            break;
                        }
                    }
                    catch (ManagementException e)
                    {
                        Logger.Instance.LogError(e.ToString());
                    }
                }
            }
            catch (ManagementException e)
            {
                Logger.Instance.LogError(e.ToString());
            }

            return(ethetnets);
        }
Ejemplo n.º 3
0
        public List <IPAddressDTOResponse> GetIPAddressInfo()
        {
            List <IPAddressDTOResponse> ipAddresses = new List <IPAddressDTOResponse>();

            try
            {
                SelectQuery query = new SelectQuery(
                    @"select MACAddress, Index 
					  from Win32_NetworkAdapter 
					  where MACAddress<>null"
                    );
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

                foreach (ManagementObject obj in searcher.Get())
                {
                    string mac = GetValueAsString(obj, "MACAddress");
                    if (Blacklists.IsMacInBlacklist(mac))
                    {
                        continue;
                    }

                    try
                    {
                        SelectQuery queryAdapterConf = new SelectQuery(
                            @"select IPAddress 
							  from Win32_NetworkAdapterConfiguration 
							  where Index='"                             + GetValueAsString(obj, "Index") + "' and IPEnabled=True"
                            );
                        ManagementObjectSearcher adapterConfSearcher = new ManagementObjectSearcher(queryAdapterConf);

                        foreach (ManagementObject adapterConf in adapterConfSearcher.Get())
                        {
                            try
                            {
                                IPAddressDTOResponse ipAddress = new IPAddressDTOResponse();
                                ipAddress.IPAddress = ((string[])adapterConf["IPAddress"])[0];

                                ipAddresses.Add(ipAddress);
                            }
                            catch (ManagementException e)
                            {
                                Logger.Instance.LogError(e.ToString());
                            }
                            catch (Exception e)
                            {
                                Logger.Instance.LogError(e.ToString());
                            }

                            break;
                        }
                    }
                    catch (ManagementException e)
                    {
                        Logger.Instance.LogError(e.ToString());
                    }
                }
            }
            catch (ManagementException e)
            {
                Logger.Instance.LogError(e.ToString());
            }

            return(ipAddresses);
        }