public void DecimalMaskDisplayAndMaskToBinaryCharArray(IP_Mask mask, TextBox textContainerForDecimalMask) { string valm = String.Format("{0}.{1}.{2}.{3}", mask.f_octet, mask.s_octet, mask.t_octet, mask.fo_octet); string valmBinary = String.Format("{0}{1}{2}{3}", Convert.ToString(mask.f_octet, 2).PadLeft(8, '0'), Convert.ToString(mask.s_octet, 2).PadLeft(8, '0'), Convert.ToString(mask.t_octet, 2).PadLeft(8, '0'), Convert.ToString(mask.fo_octet, 2).PadLeft(8, '0')); maskBinaryCharArray = valmBinary.ToCharArray(); for (int i = 0; i < maskBinaryCharArray.Length; i++) { if (maskBinaryCharArray[i].Equals('1')) { maskFlags[i] = true; } else { maskFlags[i] = false; } } textContainerForDecimalMask.Text = valm; }
public static IP_Mask GetIP_Mask(int cidr) { IP_Mask mask; byte[] bit_decimal = new byte[] { 0, 128, 192, 224, 240, 248, 252, 254, 255 }; if (cidr <= 8) { byte first = bit_decimal[cidr]; mask = new IP_Mask(first, 0, 0, 0); } else if (cidr > 8 && cidr <= 16) { int pwr = cidr - 8; byte second = bit_decimal[pwr]; mask = new IP_Mask(255, second, 0, 0); } else if (cidr > 16 && cidr <= 24) { int pwr = cidr - 16; byte third = bit_decimal[pwr]; mask = new IP_Mask(255, 255, third, 0); } else if (cidr > 24 && cidr <= 32) { int pwr = cidr - 24; byte fourth = bit_decimal[pwr]; mask = new IP_Mask(255, 255, 255, fourth); } else { mask = new IP_Mask(0, 0, 0, 0); } return(mask); }
public void MaxIpDisplay(IP_Mask mask, TextBox textContainerForMaxIp) { textContainerForMaxIp.Text = String.Format("{0}.{1}.{2}.{3}", mask.firstmaxoctet.ToString(), mask.secondmaxoctet.ToString(), mask.thirdmaxoctet.ToString(), (mask.fourthmaxoctet - 1).ToString()); }
public void BroadcastDisplay(IP_Mask mask, TextBox textContainerForBroadcast) { textContainerForBroadcast.Text = String.Format("{0}.{1}.{2}.{3}", mask.firstmaxoctet.ToString(), mask.secondmaxoctet.ToString(), mask.thirdmaxoctet.ToString(), mask.fourthmaxoctet.ToString()); }