Пример #1
0
 public IPv4(Octet FirstOctet = null, Octet SecondOctet = null, Octet ThirdOctet = null, Octet FourthOctet = null, int suffix = 0)
     : base(FirstOctet, SecondOctet, ThirdOctet, FourthOctet, suffix)
 {
     this.SubnetMask         = new SubnetMask(this.Suffix);
     this.DecimalStringValue = $"{this.ToDecimalString()}/{this.Suffix}";
     this.NetworkClass       = GetNetWorkClass();
     this.NetAddress         = GetNetAddress();
 }
Пример #2
0
        private static void WriteNetAddressFormat(VLSM.IPv4 ip, VLSM_Units vlsm_units)
        {
            Guides += $"{Environment.NewLine}";
            Guides += $@"       Subnet format:     ";


            List <int> listBits = ip.ToBinaryList();


            int startOctet = (32 - vlsm_units.BeforeHosts) / 8;
            int endOctet   = (32 - vlsm_units.AfterHosts - 1) / 8;

            int startIndex = (32 - vlsm_units.BeforeHosts);
            int endIndex   = (32 - vlsm_units.AfterHosts - 1);



            for (int i = 0; i < listBits.Count; ++i)
            {
                int currentOctetIndex = i / 8;


                if (currentOctetIndex >= startOctet && currentOctetIndex <= endOctet)
                {
                    if (i >= startIndex && i <= endIndex)
                    {
                        Guides += 'x';
                    }
                    else
                    {
                        Guides += $"{listBits[i]}";
                    }
                }
                else
                {
                    if ((i + 1) % 8 == 0)
                    {
                        Guides += $"{Octet.ToDecimal(listBits.GetRange(i - 7, 8))}";
                    }
                }


                if ((i + 1) % 8 == 0)
                {
                    if (i != 31)
                    {
                        Guides += '.';
                    }
                }
            }

            Guides += $"/{ip.Suffix + vlsm_units.BorrowedBitsAmount}";
        }
Пример #3
0
        public IP(Octet FirstOctet = null, Octet SecondOctet = null, Octet ThirdOctet = null, Octet FourthOctet = null, int suffix = 0)
        {
            this.FirstOctet  = (FirstOctet == null ? new Octet() : FirstOctet);
            this.SecondOctet = (SecondOctet == null ? new Octet() : SecondOctet);
            this.ThirdOctet  = (ThirdOctet == null ? new Octet() : ThirdOctet);
            this.FourthOctet = (FourthOctet == null ? new Octet() : FourthOctet);

            this.Suffix = suffix;


            if (FirstOctet != null)
            {
                this.NetworkClass = GetNetWorkClass();
            }
        }
Пример #4
0
        private static void WriteHostFormat(VLSM.IPv4 ip, VLSM_Units vlsm_units)
        {
            Guides += $"{Environment.NewLine}";
            Guides += $@"       Host format:     ";


            List <int> listBits       = ip.ToBinaryList();
            int        hostOctetIndex = (32 - vlsm_units.AfterHosts) / 8;


            for (int i = 0; i < 32; ++i)
            {
                if (i / 8 >= hostOctetIndex)
                {
                    if (i >= 32 - vlsm_units.AfterHosts)
                    {
                        Guides += 'x';
                    }
                    else
                    {
                        Guides += listBits[i];
                    }
                }
                else
                {
                    if (((i + 1) % 8) == 0)
                    {
                        Guides += Octet.ToDecimal(listBits.GetRange(i - 7, 8));
                    }
                }


                if (((i + 1) % 8) == 0)
                {
                    if (i != 31)
                    {
                        Guides += ".";
                    }
                }
            }


            Guides += $"/{ip.Suffix}";
        }
Пример #5
0
        public IPv4(string text)
        {
            //  format: x.x.x.x/x       -   Ex: 192.168.0.1/24

            text = text.Replace('/', '.');
            string[] segments = text.TrimEnd().Split('.');


            this.FirstOctet.ListBits  = Octet.DecimalToBinary(int.Parse(segments[0]));
            this.SecondOctet.ListBits = Octet.DecimalToBinary(int.Parse(segments[1]));
            this.ThirdOctet.ListBits  = Octet.DecimalToBinary(int.Parse(segments[2]));
            this.FourthOctet.ListBits = Octet.DecimalToBinary(int.Parse(segments[3]));


            this.Suffix             = int.Parse(segments.Last());
            this.SubnetMask         = new SubnetMask(this.Suffix);
            this.DecimalStringValue = $"{this.ToDecimalString()}/{this.Suffix}";
            this.NetAddress         = GetNetAddress();
            this.NetworkClass       = GetNetWorkClass();
        }
Пример #6
0
 public int ToDecimal()
 {
     return Octet.ToDecimal(this.ListBits);
 }
Пример #7
0
 public BinaryNumber(Decimal decimalNumber)
 {
     Octet o = new Octet((int)decimalNumber);
     this.ListBits = o.ListBits;
 }