Пример #1
0
        private void macAddressAllowedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CRUDResult res = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "macallowed/get_all");

            if (res.result)
            {
                ServerResult sr = JsonConvert.DeserializeObject <ServerResult>(res.data);
                if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
                {
                    MacAddressList wind = new MacAddressList();
                    wind.G        = this.G;
                    wind.mac_data = sr.macallowed;

                    wind.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show(StringResource.CANNOT_CONNECT_TO_SERVER, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        internal List <MacAddressList> FindAllMacAddressOnLan()
        {
            const int minMacAddrLength = 12;
            var       macAddress       = string.Empty;
            var       maxSpeed         = -1;
            var       listAllMac       = new List <MacAddressList>();

            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                var    ipProps   = nic.GetIPProperties();
                var    ipAddress = string.Empty;
                string tempMac   = nic.GetPhysicalAddress().ToString();

                if (nic.Speed > maxSpeed && !string.IsNullOrEmpty(tempMac) && tempMac.Length >= minMacAddrLength)
                {
                    foreach (var ip in ipProps.UnicastAddresses)
                    {
                        if ((nic.OperationalStatus == OperationalStatus.Up) && (ip.Address.AddressFamily == AddressFamily.InterNetwork))
                        {
                            ipAddress = ip.Address.ToString();
                        }
                    }

                    var validMac = new MacAddressList
                    {
                        NicName       = nic.Description,
                        IpAddress     = ipAddress,
                        MacId         = nic.GetPhysicalAddress().ToString(),
                        NicSpeed      = nic.Speed,
                        InterfaceType = nic.NetworkInterfaceType.ToString()
                    };

                    if ((nic.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet) && validMac.IpAddress.Length > 1)
                    {
                        listAllMac.Add(validMac);
                    }
                }
            }
            return(listAllMac);
        }