Example #1
0
        public static string GetSubnet(ListBox AdapterList)
        {
            if (AdapterList.SelectedItem == null)
            {
                if (AdapterList.Items.Count == 0)
                {
                    if (!AdapterHandler.GetAdapters(AdapterList))
                    {
                        MessageBox.Show("Can't automatically derive subnet as no adapters could be found");
                        return(null);
                    }
                }
                AdapterList.SelectedItem = AdapterList.Items[0];
            }

            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                foreach (UnicastIPAddressInformation ip in nic.GetIPProperties().UnicastAddresses)
                {
                    if (nic.Name == AdapterList.SelectedItem.ToString())
                    {
                        if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            return(FilterToSubnet(ip.Address.ToString()));
                        }
                    }
                }
            }
            return("not found");
        }
Example #2
0
 private void RefreshAdapters_Click(object sender, EventArgs e)
 {
     AdapterHandler.GetAdapters(AdapterList);
 }
Example #3
0
 private void Form1_Load(object sender, EventArgs e)
 {
     AdapterHandler.GetAdapters(AdapterList);
 }