/// Unpacks and writes out the FullNetwork file, returns the filepath 
        /// </summary>
        /// <param name="Network"></param>
        /// <param name="Path"></param>
        public string WriteOutExcelDocument(FullNetwork Network, string FileName)
        {
            // Build data table from the Network
            DataTable Table = new DataTable();
            Table.Columns.Add("Network ID");
            Table.Columns.Add("First Usable");
            Table.Columns.Add("Last Usable");
            Table.Columns.Add("Broadcast Address");

            foreach (var subnet in Network.Subnets)
            {
                // Add the data to each collumn
                DataRow Row = Table.NewRow();

                Row[0] = subnet.NetworkId;
                Row[1] = subnet.FirstUsable;
                Row[2] = subnet.LastUsable;
                Row[3] = subnet.BroadcastAddress;
                Table.Rows.Add(Row);
            }

            string FilePath = FileName + ".xlsx";

            XLWorkbook wb = new XLWorkbook();
            wb.Worksheets.Add(Table, "Subnet Data");
            wb.SaveAs(FilePath);

            return FilePath;
        }
        public SubnettingOutput(FullNetwork Network)
        {
            InitializeComponent();
            _Network = Network;
            AddressClassTextBox.Text = Network.Class.ToString();
            SubnetMaskTextBox.Text = Network.NetMask.ToString();
            AddressSpaceTextBox.Text = Network.AddressSpace.ToString();
            BitsBorrowedTextBox.Text = Network.BitsBorrowed.ToString();
            NumberOfSubnetsTextBox.Text = Network.NumberOfSubnets.ToString();
            UsableHostsPerSubnetTextBox.Text = Network.UsableHosts.ToString();

            if (Network.Class.ToString() != "C")
            {
                ExportToExcelButton.Visibility = Visibility.Hidden;
            }
        }
        /// <summary>
        /// Writes out subnet data to the working directory
        /// </summary>
        /// <param name="Network"></param>
        public void WriteSubnetData(FullNetwork Network)
        {
            StreamWriter SubnetFile = new StreamWriter("SubnetData.txt");
            SubnetFile.Write("Network ID  First Usable  Last Usable  Broadcast Address \n");
            foreach (var subnet in Network.Subnets)
            {
                StringBuilder Builder = new StringBuilder();

                Builder.Append(subnet.NetworkId + " ");
                Builder.Append(subnet.FirstUsable + " ");
                Builder.Append(subnet.LastUsable + " ");
                Builder.Append(subnet.BroadcastAddress + " \n");
                string line = Builder.ToString();
                SubnetFile.Write(line);
            }

            SubnetFile.Close();
        }
        public NetworkBuilder(NetworkInfo Info)
        {
            //// Get the nessecary data to build the subnetting information

            //int NumberOfHostsNeeded = Info.NumberOfHosts;

            //// The nessecary address class for the number of subnets and the required hosts per subnet
            //AddressClass InetClass = DetermineNessecaryAddressClass(NumberOfHostsNeeded);

            //// Uses 2^x to determine how many bits need to be borrowed
            //int BitsToBorrow = DetermineBitsToBorrow(NumberOfHostsNeeded, InetClass);

            //int BitsForAddressSpace = DetermineBitsForAddressSpace(BitsToBorrow, InetClass);

            //int RequiredSubnets = DetermineNumberOfSubnets(BitsToBorrow, InetClass);

            int BitsToBorrow = DetermineBitsToBorrow(Info.RequiredSubnets);

            AddressClass InetClass = DetermineNessecaryAddressClass(Info.NumberOfHosts);

            int AddressSpaceBits = DetermineBitsForAddressSpace(BitsToBorrow, InetClass);

            int RequiredSubnets = IntPow(2, BitsToBorrow);

            // Gets the subnet mask using data resources basedo n the required bits to borrow
            SubnetMask NetMask = GetSubnetAddress(InetClass, BitsToBorrow, AddressSpaceBits);
            IpAddress SampleAddress = new IpAddress(Info.SampleAddress);

            // The program has different functionallity based on different address class
            // For Class C it will be able to build the entire subnet out
            // For the other classes it will display generic subnetting information but not build a subnet
            switch (InetClass)
            {
                case AddressClass.A:
                    BuiltNetwork = new FullNetwork();
                    // Gather network information for Class A
                    //ClassAandBBuilder ClassABuilder = new ClassAandBBuilder();
                    //ClassABuilder.NetMask = NetMask;
                    //ClassABuilder.HostsPerSubnet = IntPow(2, (AddressSpaceBits - 2) );
                    //ClassABuilder.NumberOfSubents = IntPow(2, BitsToBorrow);
                    //BuiltNetwork.ClassAorBBuilder = ClassABuilder;
                    BuiltNetwork = new FullNetwork();
                    BuiltNetwork.BitsBorrowed = BitsToBorrow;
                    BuiltNetwork.Class = InetClass;
                    BuiltNetwork.NetMask = NetMask;
                    BuiltNetwork.NumberOfSubnets = IntPow(2, BitsToBorrow);
                    BuiltNetwork.AddressSpace = IntPow(2, AddressSpaceBits);
                    BuiltNetwork.UsableHosts = IntPow(2, AddressSpaceBits) - 2;
                    break;
                case AddressClass.B:
                    //BuiltNetwork = new FullNetwork();
                    //ClassAandBBuilder ClassBBuilder = new ClassAandBBuilder();
                    //ClassBBuilder.NetMask = NetMask;
                    //ClassBBuilder.HostsPerSubnet = IntPow(2, AddressSpaceBits);
                    //ClassBBuilder.NumberOfSubents = IntPow(2, BitsToBorrow);
                    //BuiltNetwork.ClassAorBBuilder = ClassBBuilder;
                    BuiltNetwork = new FullNetwork();
                    BuiltNetwork.BitsBorrowed = BitsToBorrow;
                    BuiltNetwork.Class = InetClass;
                    BuiltNetwork.NetMask = NetMask;
                    BuiltNetwork.NumberOfSubnets = IntPow(2, BitsToBorrow);
                    BuiltNetwork.AddressSpace = IntPow(2, AddressSpaceBits);
                    BuiltNetwork.UsableHosts = IntPow(2, AddressSpaceBits) - 2;
                    break;
                case AddressClass.C:
                    // Gather network information for Class C
                    int SubnetCount = 0;
                    BuiltNetwork = new FullNetwork();
                    // Begin the subnet building process
                    ClassCSubnetBuilder ClassCBuilder = new ClassCSubnetBuilder(NetMask, SampleAddress);
                    // Subtraction by one because it is a based of zero
                    while (SubnetCount < RequiredSubnets)
                    {
                        SubnetCount += 1;
                        Subnetwork Subnet = ClassCBuilder.NextSubnet();
                        BuiltNetwork.Subnets.Enqueue(Subnet);
                    }

                    BuiltNetwork.BitsBorrowed = BitsToBorrow;
                    BuiltNetwork.Class = InetClass;
                    BuiltNetwork.NetMask = NetMask;
                    BuiltNetwork.NumberOfSubnets = IntPow(2, BitsToBorrow);
                    BuiltNetwork.AddressSpace = (IntPow(2, AddressSpaceBits) * BuiltNetwork.NumberOfSubnets);
                    BuiltNetwork.UsableHosts = IntPow(2, AddressSpaceBits) - 2;

                    break;
                default:
                    break;
            }
        }
Beispiel #5
0
        public NetworkBuilder(NetworkInfo Info)
        {
            //// Get the nessecary data to build the subnetting information

            //int NumberOfHostsNeeded = Info.NumberOfHosts;

            //// The nessecary address class for the number of subnets and the required hosts per subnet
            //AddressClass InetClass = DetermineNessecaryAddressClass(NumberOfHostsNeeded);

            //// Uses 2^x to determine how many bits need to be borrowed
            //int BitsToBorrow = DetermineBitsToBorrow(NumberOfHostsNeeded, InetClass);

            //int BitsForAddressSpace = DetermineBitsForAddressSpace(BitsToBorrow, InetClass);

            //int RequiredSubnets = DetermineNumberOfSubnets(BitsToBorrow, InetClass);

            int BitsToBorrow = DetermineBitsToBorrow(Info.RequiredSubnets);

            AddressClass InetClass = DetermineNessecaryAddressClass(Info.NumberOfHosts);

            int AddressSpaceBits = DetermineBitsForAddressSpace(BitsToBorrow, InetClass);

            int RequiredSubnets = IntPow(2, BitsToBorrow);

            // Gets the subnet mask using data resources basedo n the required bits to borrow
            SubnetMask NetMask       = GetSubnetAddress(InetClass, BitsToBorrow, AddressSpaceBits);
            IpAddress  SampleAddress = new IpAddress(Info.SampleAddress);


            // The program has different functionallity based on different address class
            // For Class C it will be able to build the entire subnet out
            // For the other classes it will display generic subnetting information but not build a subnet
            switch (InetClass)
            {
            case AddressClass.A:
                BuiltNetwork = new FullNetwork();
                // Gather network information for Class A
                //ClassAandBBuilder ClassABuilder = new ClassAandBBuilder();
                //ClassABuilder.NetMask = NetMask;
                //ClassABuilder.HostsPerSubnet = IntPow(2, (AddressSpaceBits - 2) );
                //ClassABuilder.NumberOfSubents = IntPow(2, BitsToBorrow);
                //BuiltNetwork.ClassAorBBuilder = ClassABuilder;
                BuiltNetwork = new FullNetwork();
                BuiltNetwork.BitsBorrowed    = BitsToBorrow;
                BuiltNetwork.Class           = InetClass;
                BuiltNetwork.NetMask         = NetMask;
                BuiltNetwork.NumberOfSubnets = IntPow(2, BitsToBorrow);
                BuiltNetwork.AddressSpace    = IntPow(2, AddressSpaceBits);
                BuiltNetwork.UsableHosts     = IntPow(2, AddressSpaceBits) - 2;
                break;

            case AddressClass.B:
                //BuiltNetwork = new FullNetwork();
                //ClassAandBBuilder ClassBBuilder = new ClassAandBBuilder();
                //ClassBBuilder.NetMask = NetMask;
                //ClassBBuilder.HostsPerSubnet = IntPow(2, AddressSpaceBits);
                //ClassBBuilder.NumberOfSubents = IntPow(2, BitsToBorrow);
                //BuiltNetwork.ClassAorBBuilder = ClassBBuilder;
                BuiltNetwork = new FullNetwork();
                BuiltNetwork.BitsBorrowed    = BitsToBorrow;
                BuiltNetwork.Class           = InetClass;
                BuiltNetwork.NetMask         = NetMask;
                BuiltNetwork.NumberOfSubnets = IntPow(2, BitsToBorrow);
                BuiltNetwork.AddressSpace    = IntPow(2, AddressSpaceBits);
                BuiltNetwork.UsableHosts     = IntPow(2, AddressSpaceBits) - 2;
                break;

            case AddressClass.C:
                // Gather network information for Class C
                int SubnetCount = 0;
                BuiltNetwork = new FullNetwork();
                // Begin the subnet building process
                ClassCSubnetBuilder ClassCBuilder = new ClassCSubnetBuilder(NetMask, SampleAddress);
                // Subtraction by one because it is a based of zero
                while (SubnetCount < RequiredSubnets)
                {
                    SubnetCount += 1;
                    Subnetwork Subnet = ClassCBuilder.NextSubnet();
                    BuiltNetwork.Subnets.Enqueue(Subnet);
                }

                BuiltNetwork.BitsBorrowed    = BitsToBorrow;
                BuiltNetwork.Class           = InetClass;
                BuiltNetwork.NetMask         = NetMask;
                BuiltNetwork.NumberOfSubnets = IntPow(2, BitsToBorrow);
                BuiltNetwork.AddressSpace    = (IntPow(2, AddressSpaceBits) * BuiltNetwork.NumberOfSubnets);
                BuiltNetwork.UsableHosts     = IntPow(2, AddressSpaceBits) - 2;

                break;

            default:
                break;
            }
        }
        static void Main(string[] args)
        {
            FullNetwork Network = new FullNetwork();

            NetworkInfo Info;
            NetworkBuilder Builder;

            Info = new NetworkInfo();
            Info.NumberOfHosts = 2046;
            Info.RequiredSubnets = 32;
            Info.SampleAddress = "172.16.2.5";
            Builder = new NetworkBuilder(Info);

            SubnetDataWriter Writer = new SubnetDataWriter();
            Writer.WriteOutExcelDocument(Builder.BuiltNetwork, "Test");
            //// Deprecated
            //Info.Class = AddressClass.B; // Deprecated
            //Info.NumberOfHosts = 14;
            //Info.RequiredSubnets = 2;
            //Info.SampleAddress = "192.168.5.23";
            //Builder = new NetworkBuilder(Info);

            //SubnetDataWriter Datawriter = new SubnetDataWriter();
            //Datawriter.WriteSubnetData(Builder.BuiltNetwork);
            //Datawriter.WriteOutExcelDocument(Builder.BuiltNetwork, "14-2");

            //Info = new NetworkInfo();
            //// Deprecated
            //Info.Class = AddressClass.B; // Deprecated
            //Info.NumberOfHosts = 14;
            //Info.RequiredSubnets = 16;
            //Info.SampleAddress = "192.168.5.23";
            //Builder = new NetworkBuilder(Info);

            //Datawriter.WriteOutExcelDocument(Builder.BuiltNetwork, "14-16");

            //Info = new NetworkInfo();
            //Info.NumberOfHosts = 126;
            //Info.RequiredSubnets = 2;
            //Info.SampleAddress = "192.168.5.23";
            //Builder = new NetworkBuilder(Info);

            //Datawriter.WriteOutExcelDocument(Builder.BuiltNetwork, "126-2");

            //Info = new NetworkInfo();
            //Info.NumberOfHosts = 62;
            //Info.RequiredSubnets = 4;
            //Info.SampleAddress = "192.168.5.23";
            //Builder = new NetworkBuilder(Info);

            //Datawriter.WriteOutExcelDocument(Builder.BuiltNetwork, "62-2");

            //Info = new NetworkInfo();
            //Info.NumberOfHosts = 30;
            //Info.RequiredSubnets = 8;
            //Info.SampleAddress = "192.168.5.23";
            //Builder = new NetworkBuilder(Info);

            //Datawriter.WriteOutExcelDocument(Builder.BuiltNetwork, "30-8");

            //Info = new NetworkInfo();
            //Info.NumberOfHosts = 6;
            //Info.RequiredSubnets = 32;
            //Info.SampleAddress = "192.168.5.23";
            //Builder = new NetworkBuilder(Info);

            //Datawriter.WriteOutExcelDocument(Builder.BuiltNetwork, "6-32");

            //Info = new NetworkInfo();
            //Info.NumberOfHosts = 2;
            //Info.RequiredSubnets = 64;
            //Info.SampleAddress = "192.168.5.23";
            //Builder = new NetworkBuilder(Info);

            //Datawriter.WriteOutExcelDocument(Builder.BuiltNetwork, "2-64");

            //Info = new NetworkInfo();
            //Info.NumberOfHosts = 15;
            //Info.RequiredSubnets = 12;
            //Info.SampleAddress = "192.168.3.2";
            //Builder = new NetworkBuilder(Info);

            //Datawriter.WriteOutExcelDocument(Builder.BuiltNetwork, "Test");
        }