Example #1
0
        public static IP_Address get_SubnetNetwork(IP_Address ip = null, int cidr = 0)
        {
            IP_Address temp_mask;

            byte[] bit_Decimal = new byte[] { 0, 128, 192, 224, 240, 248, 252, 254, 255 };

            byte firstOctet  = ip.first_Octet;
            byte secondOctet = ip.second_Octet;
            byte thirdOctet  = ip.third_Octet;
            byte fourthOctet = ip.fourth_Octet;

            if (cidr <= 8)
            {
                int  pwr   = cidr;
                byte first = bit_Decimal[pwr];
                temp_mask = new IP_Address(first, 0, 0, 0);
            }
            else if (cidr <= 16 && cidr > 8)
            {
                int  pwr    = cidr - 8;
                byte second = bit_Decimal[pwr];
                temp_mask = new IP_Address(255, second, 0, 0);
            }
            else if (cidr <= 24 && cidr > 16)
            {
                int  pwr   = cidr - 16;
                byte third = bit_Decimal[pwr];
                temp_mask = new IP_Address(255, 255, third, 0);
            }
            else if (cidr <= 32 && cidr > 24)
            {
                int  pwr    = cidr - 24;
                byte fourth = bit_Decimal[pwr];
                temp_mask = new IP_Address(255, 255, 255, fourth);
            }
            else
            {
                temp_mask = new IP_Address(0, 0, 0, 0);
            }

            IP_Address subnet = new IP_Address((byte)(temp_mask.first_Octet & ip.first_Octet),
                                               (byte)(temp_mask.second_Octet & ip.second_Octet),
                                               (byte)(temp_mask.third_Octet & ip.third_Octet),
                                               (byte)(temp_mask.fourth_Octet & ip.fourth_Octet));

            return(subnet);
        }
Example #2
0
 public string get_class(IP_Address IP)
 {
     if (IP.first_Octet <= 126 && IP.first_Octet > 1)
     {
         return("Class A");
     }
     if (IP.first_Octet <= 191 && IP.first_Octet > 128)
     {
         return("Class B");
     }
     if (IP.first_Octet <= 223 && IP.first_Octet > 192)
     {
         return("Class C");
     }
     if (IP.first_Octet == 127)
     {
         return("LoopBack");
     }
     return("INVALID IP ADDRESS");
 }
Example #3
0
        private void cal_Subnet_Click(object sender, RoutedEventArgs e)
        {
            ComboBoxItem a            = (ComboBoxItem)IP1stOctet.SelectedItem;
            byte         ip_1st_octet = Byte.Parse((string)a.Content);

            a = (ComboBoxItem)IP2ndOctet.SelectedItem;
            byte ip_2nd_octet = Byte.Parse((string)a.Content);

            a = (ComboBoxItem)IP3rdOctet.SelectedItem;
            byte ip_3rd_octet = Byte.Parse((string)a.Content);

            a = (ComboBoxItem)IP4thOctet.SelectedItem;
            byte ip_4th_octet = Byte.Parse((string)a.Content);
            int  cidr         = int.Parse((string)((ComboBoxItem)CIDRcomboBox.SelectedItem).Content);

            IP_Address ip = new IP_Address(ip_1st_octet, ip_2nd_octet, ip_3rd_octet, ip_4th_octet);

            IP_Address subnet = IP_config.get_SubnetNetwork(ip, cidr);

            string sub = String.Format("{0}.{1}.{2}.{3}", subnet.first_Octet,
                                       subnet.second_Octet, subnet.third_Octet, subnet.fourth_Octet);

            SubnetTextBlock.Text = sub;
        }