Search Forum
(53671 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


 
Printable Version

IP Address Calculator
By by Gustavo Parés

This article is a brief introduction to the ip version 4 addressing scheme. The source code of a program that converts IP network address numbers to binary format, as well as converts from binary to decimal. It also calculates depending on the network mask how many subnets and hosts could be on a network number. It also shows what type of network it is A,B,C,D or E. Depending on the ip address. It shows in a simple tree depending on the network mask what portion of the address correspondes to the network, to the subnet and to the host.

An IP address is made up of 32 bits of information. These bits are divided into four sections containing 1 byte (8 bits) each. These sections are referred to as octets. There are 3 methods for depicting an IP address in:

Format

IP Address

Decimal:

155.57.1.56

Binary:

10000010.00111001.00000001.00111000

Hexadecimal:

9B.39.01.38

All of these examples represent the same IP address.

The 32-bit IP address is a structured or hierarchical address, in contrast to a flat address like the MAC address of the NIC (Network Interface Card). A flat addressing scheme is like the social security number, where there is no partitioning. A hierarchical example could be the area code numbers of telephone lines. The advantage of this scheme is that it can handle a large number of addresses, namely 4.2 billion (a 32-bit address space with tow possible values for each position).  This scheme uses a 3 level hierarchical addressing shceme structured by network, subnet and host. The network address uniquely identifies each network.  The node address or host address identifies each machine on a network.

 

Class

Format

Leading bit  pattern        

Decimal range of first byte of a network address                     

Maximum networks Maximum nodes per network

A

Net.Node.Node.Node

0

1-127      

127

16,777,214

B

Net.Net.Node.Node

10

128-191

16,384

65,534

C

Net.Net.Net.Node

110

192-223

2,097,152

254

Source Code

Students who are learning networking theory could find very helpfull a program that converts the ip network address from a decimal format ))(186.124.65.0) to binary (10111010.1111100.1000001.0) , as well as from binary to decimal. This conversion is usefull to determine subnet ranges as well as broadcast addresses.

//+++++++++++++++++++SOURCE CODE+++++++++++++++++

  • using System;

    using System.Drawing;

    using System.Collections;

    using System.ComponentModel;

    using System.Windows.Forms;

    using System.Data;

     

    namespace Redes

    {

    /// <summary>

    /// IP Calculator by Gustavo Parés (gus_ksh@hotmail.com)

    ///

    /// This program converts IP network address

    /// numbers to binary format, as well as converts from binary to decimal.

    /// It also calculates depending on the network mask how many subnets

    /// and hosts could be on a network number. It also shows what type of

    /// network it is A,B,C,D or E. Depending on the ip address. It shows in

    /// a simple tree depending on the network mask what portion of the address

    /// correspondes to the network, to the subnet and to the host.

    /// </summary>

    ///

    public class IPcalculator : System.Windows.Forms.Form

    {

    bool yaMostro = false;

    private System.Windows.Forms.TextBox textBox1;

    private System.Windows.Forms.TextBox textBox2;

    private System.Windows.Forms.TextBox textBox3;

    private System.Windows.Forms.Label label1;

    private System.Windows.Forms.TextBox textBox4;

    private System.Windows.Forms.TextBox textBox5;

    private System.Windows.Forms.Label label2;

    private System.Windows.Forms.TextBox textBox6;

    private System.Windows.Forms.TextBox textBox7;

    private System.Windows.Forms.TextBox textBox8;

    private System.Windows.Forms.TextBox textBox9;

    private System.Windows.Forms.Label label3;

    private System.Windows.Forms.Label label4;

    private System.Windows.Forms.TextBox textBox13;

    private System.Windows.Forms.Label label5;

    private System.Windows.Forms.TextBox hosts;

    private System.Windows.Forms.TextBox subredes;

    private System.Windows.Forms.Label label6;

    private System.Windows.Forms.Button button2;

    private System.Windows.Forms.RichTextBox explicacion;

    private System.Windows.Forms.Label label7;

    private System.Windows.Forms.Label label8;

    private System.Windows.Forms.RichTextBox netMaskDecimal;

    private System.Windows.Forms.PictureBox pictureBox1;

    private System.Windows.Forms.Button button3;

    private System.Windows.Forms.TreeView tree;

    private System.Drawing.Printing.PrintDocument printDocument1;

    private System.Windows.Forms.MainMenu mainMenu1;

    private System.Windows.Forms.MenuItem menuItem1;

    private System.Windows.Forms.MenuItem menuItem2;

    private System.Windows.Forms.MenuItem menuItem3;

    private System.Windows.Forms.MenuItem menuItem4;

    private System.Windows.Forms.MenuItem menuItem9;

    private System.Windows.Forms.Button btnConvertDecimal;

    /// <summary>

    /// Required designer variable.

    /// </summary>

    private System.ComponentModel.Container components = null;

    public IPcalculator()

    {

    InitializeComponent();

    }

    /// <summary>

    /// Clean up any resources being used.

    /// </summary>

    protected override void Dispose( bool disposing )

    {

    if( disposing )

    {

    if (components != null)

    {

    components.Dispose();

    }

    }

    base.Dispose( disposing );

    }

    #region Windows Form Designer generated code

    /// <summary>

    /// Required method for Designer support - do not modify

    /// the contents of this method with the code editor.

    /// </summary>

    private void InitializeComponent()

    {

    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(IPcalculator));

    this.btnConvertDecimal = new System.Windows.Forms.Button();

    this.textBox1 = new System.Windows.Forms.TextBox();

    this.textBox2 = new System.Windows.Forms.TextBox();

    this.textBox3 = new System.Windows.Forms.TextBox();

    this.label1 = new System.Windows.Forms.Label();

    this.textBox4 = new System.Windows.Forms.TextBox();

    this.textBox5 = new System.Windows.Forms.TextBox();

    this.label2 = new System.Windows.Forms.Label();

    this.textBox6 = new System.Windows.Forms.TextBox();

    this.textBox7 = new System.Windows.Forms.TextBox();

    this.textBox8 = new System.Windows.Forms.TextBox();

    this.textBox9 = new System.Windows.Forms.TextBox();

    this.label3 = new System.Windows.Forms.Label();

    this.label4 = new System.Windows.Forms.Label();

    this.textBox13 = new System.Windows.Forms.TextBox();

    this.label5 = new System.Windows.Forms.Label();

    this.hosts = new System.Windows.Forms.TextBox();

    this.subredes = new System.Windows.Forms.TextBox();

    this.label6 = new System.Windows.Forms.Label();

    this.button2 = new System.Windows.Forms.Button();

    this.explicacion = new System.Windows.Forms.RichTextBox();

    this.label7 = new System.Windows.Forms.Label();

    this.label8 = new System.Windows.Forms.Label();

    this.netMaskDecimal = new System.Windows.Forms.RichTextBox();

    this.pictureBox1 = new System.Windows.Forms.PictureBox();

    this.tree = new System.Windows.Forms.TreeView();

    this.button3 = new System.Windows.Forms.Button();

    this.printDocument1 = new System.Drawing.Printing.PrintDocument();

    this.mainMenu1 = new System.Windows.Forms.MainMenu();

    this.menuItem1 = new System.Windows.Forms.MenuItem();

    this.menuItem2 = new System.Windows.Forms.MenuItem();

    this.menuItem3 = new System.Windows.Forms.MenuItem();

    this.menuItem4 = new System.Windows.Forms.MenuItem();

    this.menuItem9 = new System.Windows.Forms.MenuItem();

    this.SuspendLayout();

    //

    // btnConvertDecimal

    //

    this.btnConvertDecimal.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;

    this.btnConvertDecimal.Location = new System.Drawing.Point(376, 232);

    this.btnConvertDecimal.Name = "btnConvertDecimal";

    this.btnConvertDecimal.Size = new System.Drawing.Size(152, 24);

    this.btnConvertDecimal.TabIndex = 0;

    this.btnConvertDecimal.Text = "Convert to Decimal";

    this.btnConvertDecimal.Visible = false;

    this.btnConvertDecimal.Click += new System.EventHandler(this.btnConvertDecimal_Click);

    this.btnConvertDecimal.MouseHover += new System.EventHandler(this.btnConvertDecimal_MouseHover);

    //

    // textBox1

    //

    this.textBox1.Location = new System.Drawing.Point(24, 256);

    this.textBox1.MaxLength = 8;

    this.textBox1.Name = "textBox1";

    this.textBox1.Size = new System.Drawing.Size(80, 20);

    this.textBox1.TabIndex = 1;

    this.textBox1.Text = "0";

    this.textBox1.ModifiedChanged += new System.EventHandler(this.textBox1_ModifiedChanged);

    this.textBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox1_MouseDown);

    this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);

    //

    // textBox2

    //

    this.textBox2.Location = new System.Drawing.Point(104, 256);

    this.textBox2.MaxLength = 8;

    this.textBox2.Name = "textBox2";

    this.textBox2.Size = new System.Drawing.Size(80, 20);

    this.textBox2.TabIndex = 2;

    this.textBox2.Text = "0";

    this.textBox2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox2_MouseDown);

    this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);

    //

    // textBox3

    //

    this.textBox3.Location = new System.Drawing.Point(184, 256);

    this.textBox3.MaxLength = 8;

    this.textBox3.Name = "textBox3";

    this.textBox3.Size = new System.Drawing.Size(80, 20);

    this.textBox3.TabIndex = 3;

    this.textBox3.Text = "0";

    this.textBox3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox3_MouseDown);

    this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged);

    //

    // label1

    //

    this.label1.BackColor = System.Drawing.Color.Blue;

    this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;

    this.label1.Location = new System.Drawing.Point(24, 232);

    this.label1.Name = "label1";

    this.label1.Size = new System.Drawing.Size(320, 24);

    this.label1.TabIndex = 4;

    this.label1.Text = "Network address in Binary (Base 2)";

    this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

    //

    // textBox4

    //

    this.textBox4.Location = new System.Drawing.Point(264, 256);

    this.textBox4.MaxLength = 8;

    this.textBox4.Name = "textBox4";

    this.textBox4.Size = new System.Drawing.Size(80, 20);

    this.textBox4.TabIndex = 4;

    this.textBox4.Text = "0";

    this.textBox4.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox4_MouseDown);

    this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged);

    //

    // textBox5

    //

    this.textBox5.Location = new System.Drawing.Point(264, 144);

    this.textBox5.MaxLength = 3;

    this.textBox5.Name = "textBox5";

    this.textBox5.Size = new System.Drawing.Size(80, 20);

    this.textBox5.TabIndex = 8;

    this.textBox5.Text = "0";

    this.textBox5.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox5_MouseDown);

    this.textBox5.TextChanged += new System.EventHandler(this.textBox5_TextChanged);

    //

    // label2

    //

    this.label2.BackColor = System.Drawing.SystemColors.ActiveCaption;

    this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;

    this.label2.Location = new System.Drawing.Point(24, 120);

    this.label2.Name = "label2";

    this.label2.Size = new System.Drawing.Size(320, 24);

    this.label2.TabIndex = 9;

    this.label2.Text = "Network address in Decimal (Base 10)";

    this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

    //

    // textBox6

    //

    this.textBox6.Location = new System.Drawing.Point(184, 144);

    this.textBox6.MaxLength = 3;

    this.textBox6.Name = "textBox6";

    this.textBox6.Size = new System.Drawing.Size(80, 20);

    this.textBox6.TabIndex = 7;

    this.textBox6.Text = "0";

    this.textBox6.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox6_MouseDown);

    this.textBox6.TextChanged += new System.EventHandler(this.textBox6_TextChanged);

    //

    // textBox7

    //

    this.textBox7.Location = new System.Drawing.Point(104, 144);

    this.textBox7.MaxLength = 3;

    this.textBox7.Name = "textBox7";

    this.textBox7.Size = new System.Drawing.Size(80, 20);

    this.textBox7.TabIndex = 6;

    this.textBox7.Text = "0";

    this.textBox7.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox7_MouseDown);

    this.textBox7.TextChanged += new System.EventHandler(this.textBox7_TextChanged);

    //

    // textBox8

    //

    this.textBox8.Location = new System.Drawing.Point(24, 144);

    this.textBox8.MaxLength = 3;

    this.textBox8.Name = "textBox8";

    this.textBox8.Size = new System.Drawing.Size(80, 20);

    this.textBox8.TabIndex = 5;

    this.textBox8.Text = "0";

    this.textBox8.ModifiedChanged += new System.EventHandler(this.button2_Click);

    this.textBox8.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox8_MouseDown);

    this.textBox8.TextChanged += new System.EventHandler(this.textBox8_TextChanged);

    //

    // textBox9

    //

    this.textBox9.BackColor = System.Drawing.SystemColors.HighlightText;

    this.textBox9.Location = new System.Drawing.Point(376, 144);

    this.textBox9.Name = "textBox9";

    this.textBox9.ReadOnly = true;

    this.textBox9.Size = new System.Drawing.Size(152, 20);

    this.textBox9.TabIndex = 10;

    this.textBox9.Text = "";

    this.textBox9.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

    this.textBox9.Visible = false;

    //

    // label3

    //

    this.label3.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));

    this.label3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;

    this.label3.Location = new System.Drawing.Point(376, 120);

    this.label3.Name = "label3";

    this.label3.Size = new System.Drawing.Size(152, 20);

    this.label3.TabIndex = 11;

    this.label3.Text = "Network Class";

    this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

    this.label3.Visible = false;

    //

    // label4

    //

    this.label4.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));

    this.label4.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;

    this.label4.Location = new System.Drawing.Point(376, 176);

    this.label4.Name = "label4";

    this.label4.Size = new System.Drawing.Size(152, 20);

    this.label4.TabIndex = 13;

    this.label4.Text = "# bits in the network mask";

    this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

    //

    // textBox13

    //

    this.textBox13.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

    this.textBox13.Location = new System.Drawing.Point(376, 200);

    this.textBox13.MaxLength = 2;

    this.textBox13.Name = "textBox13";

    this.textBox13.Size = new System.Drawing.Size(152, 23);

    this.textBox13.TabIndex = 14;

    this.textBox13.Text = "0";

    this.textBox13.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

    this.textBox13.TextChanged += new System.EventHandler(this.textBox13_TextChanged);

    //

    // label5

    //

    this.label5.BackColor = System.Drawing.Color.Red;

    this.label5.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;

    this.label5.Location = new System.Drawing.Point(192, 344);

    this.label5.Name = "label5";

    this.label5.Size = new System.Drawing.Size(152, 20);

    this.label5.TabIndex = 16;

    this.label5.Text = "Number of available hosts";

    this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

    this.label5.Visible = false;

    //

    // hosts

    //

    this.hosts.BackColor = System.Drawing.SystemColors.HighlightText;

    this.hosts.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

    this.hosts.Location = new System.Drawing.Point(192, 368);

    this.hosts.Name = "hosts";

    this.hosts.ReadOnly = true;

    this.hosts.Size = new System.Drawing.Size(152, 23);

    this.hosts.TabIndex = 15;

    this.hosts.Text = "";

    this.hosts.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

    this.hosts.Visible = false;

    //

    // subredes

    //

    this.subredes.BackColor = System.Drawing.SystemColors.HighlightText;

    this.subredes.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

    this.subredes.Location = new System.Drawing.Point(24, 368);

    this.subredes.Name = "subredes";

    this.subredes.ReadOnly = true;

    this.subredes.Size = new System.Drawing.Size(152, 23);

    this.subredes.TabIndex = 17;

    this.subredes.Text = "";

    this.subredes.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

    this.subredes.Visible = false;

    //

    // label6

    //

    this.label6.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(128)), ((System.Byte)(0)));

    this.label6.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;

    this.label6.Location = new System.Drawing.Point(24, 344);

    this.label6.Name = "label6";

    this.label6.Size = new System.Drawing.Size(152, 20);

    this.label6.TabIndex = 18;

    this.label6.Text = "Number of subnets available";

    this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

    this.label6.Visible = false;

    //

    // button2

    //

    this.button2.Location = new System.Drawing.Point(376, 264);

    this.button2.Name = "button2";

    this.button2.Size = new System.Drawing.Size(152, 24);

    this.button2.TabIndex = 19;

    this.button2.Text = "Convert to Binary";

    this.button2.Visible = false;

    this.button2.Click += new System.EventHandler(this.button2_Click);

    this.button2.MouseHover += new System.EventHandler(this.button2_MouseHover);

    //

    // explicacion

    //

    this.explicacion.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

    this.explicacion.Location = new System.Drawing.Point(24, 312);

    this.explicacion.Name = "explicacion";

    this.explicacion.ReadOnly = true;

    this.explicacion.Size = new System.Drawing.Size(320, 24);

    this.explicacion.TabIndex = 20;

    this.explicacion.Text = "";

    //

    // label7

    //

    this.label7.BackColor = System.Drawing.Color.Blue;

    this.label7.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;

    this.label7.Location = new System.Drawing.Point(24, 288);

    this.label7.Name = "label7";

    this.label7.Size = new System.Drawing.Size(320, 24);

    this.label7.TabIndex = 21;

    this.label7.Text = "Network Mask in Binario (Base 2)";

    this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

    //

    // label8

    //

    this.label8.BackColor = System.Drawing.SystemColors.ActiveCaption;

    this.label8.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;

    this.label8.Location = new System.Drawing.Point(24, 176);

    this.label8.Name = "label8";

    this.label8.Size = new System.Drawing.Size(320, 24);

    this.label8.TabIndex = 23;

    this.label8.Text = "Network mask in Decimal (Base 10)";

    this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

    //

    // netMaskDecimal

    //

    this.netMaskDecimal.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

    this.netMaskDecimal.Location = new System.Drawing.Point(24, 200);

    this.netMaskDecimal.Name = "netMaskDecimal";

    this.netMaskDecimal.ReadOnly = true;

    this.netMaskDecimal.Size = new System.Drawing.Size(320, 24);

    this.netMaskDecimal.TabIndex = 22;

    this.netMaskDecimal.Text = "";

    //

    // pictureBox1

    //

    this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));

    this.pictureBox1.Name = "pictureBox1";

    this.pictureBox1.Size = new System.Drawing.Size(608, 104);

    this.pictureBox1.TabIndex = 24;

    this.pictureBox1.TabStop = false;

    //

    // tree

    //

    this.tree.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

    this.tree.ImageIndex = -1;

    this.tree.Location = new System.Drawing.Point(376, 328);

    this.tree.Name = "tree";

    this.tree.SelectedImageIndex = -1;

    this.tree.Size = new System.Drawing.Size(152, 72);

    this.tree.TabIndex = 25;

    this.tree.Click += new System.EventHandler(this.tree_Click);

    this.tree.DoubleClick += new System.EventHandler(this.tree_DoubleClick);

    //

    // button3

    //

    this.button3.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;

    this.button3.Location = new System.Drawing.Point(376, 296);

    this.button3.Name = "button3";

    this.button3.Size = new System.Drawing.Size(152, 24);

    this.button3.TabIndex = 26;

    this.button3.Text = "Show Tree";

    this.button3.Click += new System.EventHandler(this.button3_Click);

    //

    // mainMenu1

    //

    this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

    this.menuItem1,

    this.menuItem4});

    //

    // menuItem1

    //

    this.menuItem1.Index = 0;

    this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

    this.menuItem2,

    this.menuItem3});

    this.menuItem1.Text = "Application";

    //

    // menuItem2

    //

    this.menuItem2.Index = 0;

    this.menuItem2.Text = "Print";

    this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);

    //

    // menuItem3

    //

    this.menuItem3.Index = 1;

    this.menuItem3.Text = "Exit";

    this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);

    //

    // menuItem4

    //

    this.menuItem4.Index = 1;

    this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

    this.menuItem9});

    this.menuItem4.Text = "About";

    //

    // menuItem9

    //

    this.menuItem9.Index = 0;

    this.menuItem9.Text = "Gustavo Pares";

    //

    // IPcalculator

    //

    this.AutoScale = false;

    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

    this.ClientSize = new System.Drawing.Size(600, 421);

    this.Controls.AddRange(new System.Windows.Forms.Control[] {

    this.button3,

    this.tree,

    this.label8,

    this.netMaskDecimal,

    this.label7,

    this.explicacion,

    this.button2,

    this.label6,

    this.subredes,

    this.label5,

    this.hosts,

    this.textBox13,

    this.label4,

    this.label3,

    this.textBox9,

    this.textBox5,

    this.label2,

    this.textBox6,

    this.textBox7,

    this.textBox8,

    this.textBox4,

    this.label1,

    this.textBox3,

    this.textBox2,

    this.textBox1,

    this.btnConvertDecimal,

    this.pictureBox1});

    this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

    this.Menu = this.mainMenu1;

    this.Name = "IPcalculator";

    this.Text = "Network IP Calculator by Gustavo Parés gus_ksh@hotmail.com";

    this.Load += new System.EventHandler(this.IPcalculator_Load);

    this.ResumeLayout(false);

    }

    #endregion

    /// <summary>

    /// The main entry point for the application.

    /// </summary>

    [STAThread]

    static void Main()

    {

    Application.Run(new IPcalculator());

    }

    private void btnConvertDecimal_Click(object sender, System.EventArgs e)

    {

    if(textBox13.Text == "")

    {

    textBox13.Text = "0";

    }

    int netMask = Convert.ToInt32(textBox13.Text);

    explicacion.Text = "";

    netMaskDecimal.Text = "";

    int i =0;

    if(netMask == 8) { netMaskDecimal.AppendText("255.0.0.0"); }

    if(netMask == 9) { netMaskDecimal.AppendText("255.128.0.0"); }

    if(netMask == 10) { netMaskDecimal.AppendText("255.192.0.0"); }

    if(netMask == 11) { netMaskDecimal.AppendText("255.224.0.0"); }

    if(netMask == 12) { netMaskDecimal.AppendText("255.240.0.0"); }

    if(netMask == 13) { netMaskDecimal.AppendText("255.248.0.0"); }

    if(netMask == 14) { netMaskDecimal.AppendText("255.252.0.0"); }

    if(netMask == 15) { netMaskDecimal.AppendText("255.254.0.0"); }

    if(netMask == 16) { netMaskDecimal.AppendText("255.255.0.0"); }

    if(netMask == 17) { netMaskDecimal.AppendText("255.255.128.0"); }

    if(netMask == 18) { netMaskDecimal.AppendText("255.255.192.0"); }

    if(netMask == 19) { netMaskDecimal.AppendText("255.255.224.0"); }

    if(netMask == 20) { netMaskDecimal.AppendText("255.255.240.0"); }

    if(netMask == 21) { netMaskDecimal.AppendText("255.255.248.0"); }

    if(netMask == 22) { netMaskDecimal.AppendText("255.255.252.0"); }

    if(netMask == 23) { netMaskDecimal.AppendText("255.255.254.0"); }

    if(netMask == 24) { netMaskDecimal.AppendText("255.255.255.0"); }

    if(netMask == 25) { netMaskDecimal.AppendText("255.255.255.128"); }

    if(netMask == 26) { netMaskDecimal.AppendText("255.255.255.192"); }

    if(netMask == 27) { netMaskDecimal.AppendText("255.255.255.224"); }

    if(netMask == 28) { netMaskDecimal.AppendText("255.255.255.240"); }

    if(netMask == 29) { netMaskDecimal.AppendText("255.255.255.248"); }

    if(netMask == 30) { netMaskDecimal.AppendText("255.255.255.252"); }

    if(netMask == 31) { netMaskDecimal.AppendText("255.255.255.254"); }

    if(netMask == 32) { netMaskDecimal.AppendText("255.255.255.255"); }

    for( i=0 ; i <netMask; i++)

    {

    if(i ==8 ||i== 16 || i== 24 || i == 32)

    {

    explicacion.AppendText(".");

    }

    explicacion.AppendText("1");

    }

    for(int x = i; x < (32); x++)

    {

    if(x ==8 || x == 16 ||x == 24 || x == 32 )

    {

    explicacion.AppendText(".");

    }

    explicacion.AppendText("0");

    }

    yaMostro = true;

    label5.Visible = true;

    label3.Visible = true;

    label6.Visible = true;

    textBox9.Visible = true;

    hosts.Visible = true;

    subredes.Visible = true;

    if(textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox13.Text != "")

    {

    int a = Convert.ToInt32(textBox1.Text, 2);

    int b = Convert.ToInt32(textBox2.Text, 2);

    int c = Convert.ToInt32(textBox3.Text, 2);

    int d = Convert.ToInt32(textBox4.Text, 2);

    int numeroHosts = (int)(Math.Pow(2, (32-netMask))-2);

    int numeroSubRedes = (int)(Math.Pow(2, (netMask))-2);

    hosts.Text = "" + numeroHosts;

    subredes.Text = "" + numeroSubRedes;

    String ax = Convert.ToString(89, 2);

    // int ax = Convert.ToInt32( textBox8.Text, 2);

    // MessageBox.Show(" Numero en binario " +ax);

    textBox8.Text ="" +a;

    textBox7.Text ="" +b;

    textBox6.Text ="" +c;

    textBox5.Text ="" +d;

    if(a < 128)

    {

    textBox9.Text = "A";

    }

    if(a >= 128 && a < 192)

    {

    textBox9.Text = "B";

    }

    if(a >= 192 && a < 224)

    {

    textBox9.Text = "C";

    }

    if(a >= 224 && a < 240)

    {

    textBox9.Text = "D";

    }

    if(a >= 240&& a <= 255)

    {

    textBox9.Text = "E";

    }

    } // termina el if de validacion

    else

    {

    MessageBox.Show("Falta introducir cierta información ", "Validación de captura - Calculadora de Redes - ITESM - CCM ", MessageBoxButtons.OK, MessageBoxIcon.Warning);

    }// termina else de validacion

    }

    private void IPcalculator_Load(object sender, System.EventArgs e)

    {

    }

    private void button2_Click(object sender, System.EventArgs e)

    {

    explicacion.Text = "";

    netMaskDecimal.Text = "";

    if(textBox13.Text == "")

    {

    textBox13.Undo();

    textBox13.Text = "0";

    }

    int netMask = Convert.ToInt32(textBox13.Text);

    explicacion.Text = "";

    netMaskDecimal.Text = "";

    int i =0;

    if(netMask == 8) { netMaskDecimal.AppendText("255.0.0.0"); }

    if(netMask == 9) { netMaskDecimal.AppendText("255.128.0.0"); }

    if(netMask == 10) { netMaskDecimal.AppendText("255.192.0.0"); }

    if(netMask == 11) { netMaskDecimal.AppendText("255.224.0.0"); }

    if(netMask == 12) { netMaskDecimal.AppendText("255.240.0.0"); }

    if(netMask == 13) { netMaskDecimal.AppendText("255.248.0.0"); }

    if(netMask == 14) { netMaskDecimal.AppendText("255.252.0.0"); }

    if(netMask == 15) { netMaskDecimal.AppendText("255.254.0.0"); }

    if(netMask == 16) { netMaskDecimal.AppendText("255.255.0.0"); }

    if(netMask == 17) { netMaskDecimal.AppendText("255.255.128.0"); }

    if(netMask == 18) { netMaskDecimal.AppendText("255.255.192.0"); }

    if(netMask == 19) { netMaskDecimal.AppendText("255.255.224.0"); }

    if(netMask == 20) { netMaskDecimal.AppendText("255.255.240.0"); }

    if(netMask == 21) { netMaskDecimal.AppendText("255.255.248.0"); }

    if(netMask == 22) { netMaskDecimal.AppendText("255.255.252.0"); }

    if(netMask == 23) { netMaskDecimal.AppendText("255.255.254.0"); }

    if(netMask == 24) { netMaskDecimal.AppendText("255.255.255.0"); }

    if(netMask == 25) { netMaskDecimal.AppendText("255.255.255.128"); }

    if(netMask == 26) { netMaskDecimal.AppendText("255.255.255.192"); }

    if(netMask == 27) { netMaskDecimal.AppendText("255.255.255.224"); }

    if(netMask == 28) { netMaskDecimal.AppendText("255.255.255.240"); }

    if(netMask == 29) { netMaskDecimal.AppendText("255.255.255.248"); }

    if(netMask == 30) { netMaskDecimal.AppendText("255.255.255.252"); }

    if(netMask == 31) { netMaskDecimal.AppendText("255.255.255.254"); }

    if(netMask == 32) { netMaskDecimal.AppendText("255.255.255.255"); }

    for( i=0 ; i <netMask; i++)

    {

    if(i ==8 ||i== 16 || i== 24 || i == 32)

    {

    explicacion.AppendText(".");

    }

    explicacion.AppendText("1");

    }

    for(int x = i; x < (32); x++)

    {

    if(x ==8 || x == 16 ||x == 24 || x == 32 )

    {

    explicacion.AppendText(".");

    }

    explicacion.AppendText("0");

    }

    // explicacion.AppendText(" Red : " + textBox1.Text + "." + textBox2.Text + "." + textBox3.Text + "." + textBox4.Text + "\n");

    yaMostro = true;

    label5.Visible = true;

    label3.Visible = true;

    label6.Visible = true;

    textBox9.Visible = true;

    hosts.Visible = true;

    subredes.Visible = true;

    if(textBox8.Text != "" && textBox7.Text != "" && textBox6.Text != "" && textBox5.Text != "" && textBox13.Text != "")

    {

    long na = Convert.ToInt64(textBox8.Text);

    long nb = Convert.ToInt64(textBox7.Text);

    long nc = Convert.ToInt64(textBox6.Text);

    long nd = Convert.ToInt64(textBox5.Text);

    String sa = Convert.ToString(na, 2);

    String sb = Convert.ToString(nb, 2);

    String sc = Convert.ToString(nc, 2);

    String sd = Convert.ToString(nd, 2);

    long a = Convert.ToInt64(sa);

    long b = Convert.ToInt64(sb);

    long c = Convert.ToInt64(sc);

    long d = Convert.ToInt64(sd);

    int numeroHosts = (int)(Math.Pow(2, (32-netMask))-2);

    int numeroSubRedes = (int)(Math.Pow(2, (netMask))-2);

    hosts.Text = "" + numeroHosts;

    subredes.Text = "" + numeroSubRedes;

    String ax = Convert.ToString(89, 2);

    // int ax = Convert.ToInt32( textBox8.Text, 2);

    // MessageBox.Show(" Numero en binario " +ax);

    textBox1.Text ="" +a;

    textBox2.Text ="" +b;

    textBox3.Text ="" +c;

    textBox4.Text ="" +d;

    if(a < 10000000)

    {

    textBox9.Text = "A";

    }

    if(a > 10000000 && a < 11000000)

    {

    textBox9.Text = "B";

    }

    if(a > 11000000 && a < 11100000)

    {

    textBox9.Text = "C";

    }

    if(a > 11100000 && a < 11110000)

    {

    textBox9.Text = "D";

    }

    if(a > 11110000&& a < 11111000)

    {

    textBox9.Text = "E";

    }

    } // termina el if de validacion

    else

    {

    MessageBox.Show("Falta introducir cierta información ", "Validación de captura - Calculadora de Redes - ITESM - CCM ", MessageBoxButtons.OK, MessageBoxIcon.Warning);

    }// termina else de validacion

    }

    private void textBox8_TextChanged(object sender, System.EventArgs e)

    {

    try

    {

    if(yaMostro == true)

    {

    label5.Visible = true;

    label3.Visible = true;

    label6.Visible = true;

    textBox9.Visible = true;

    hosts.Visible = true;

    subredes.Visible = true;

    if(textBox8.Text != "")

    {

    long na = Convert.ToInt64(textBox8.Text);

    long nb = Convert.ToInt64(textBox7.Text);

    long nc = Convert.ToInt64(textBox6.Text);

    long nd = Convert.ToInt64(textBox5.Text);

    String sa = Convert.ToString(na, 2);

    String sb = Convert.ToString(nb, 2);

    String sc = Convert.ToString(nc, 2);

    String sd = Convert.ToString(nd, 2);

    int a = Convert.ToInt32(sa);

    int b = Convert.ToInt32(sb);

    int c = Convert.ToInt32(sc);

    int d = Convert.ToInt32(sd);

    int netMask = Convert.ToInt32(textBox13.Text);

    int numeroHosts = (int)(Math.Pow(2, (32-netMask))-2);

    int numeroSubRedes = (int)(Math.Pow(2, (netMask))-2);

    hosts.Text = "" + numeroHosts;

    subredes.Text = "" + numeroSubRedes;

    String ax = Convert.ToString(89, 2);

    // int ax = Convert.ToInt32( textBox8.Text, 2);

    // MessageBox.Show(" Numero en binario " +ax);

    textBox1.Text ="" +a;

    textBox2.Text ="" +b;

    textBox3.Text ="" +c;

    textBox4.Text ="" +d;

    if(a < 128)

    {

    textBox9.Text = "A";

    }

    if(a >= 128 && a < 192)

    {

    textBox9.Text = "B";

    }

    if(a >= 192 && a < 224)

    {

    textBox9.Text = "C";

    }

    if(a >= 224 && a < 240)

    {

    textBox9.Text = "D";

    }

    if(a >= 240&& a <= 255)

    {

    textBox9.Text = "E";

    }

    } // termina el if de validacion

    else

    {

    textBox8.Undo();

    }// termina else de validacion

    }// Termina if yaMostro

    }

    catch(Exception ex)

    {MessageBox.Show( ex.ToString());}

    }

    private void textBox7_TextChanged(object sender, System.EventArgs e)

    {

    if(yaMostro == true)

    {

    label5.Visible = true;

    label3.Visible = true;

    label6.Visible = true;

    textBox9.Visible = true;

    hosts.Visible = true;

    subredes.Visible = true;

    if( textBox7.Text != "" )

    {

    int na = Convert.ToInt32(textBox8.Text);

    int nb = Convert.ToInt32(textBox7.Text);

    int nc = Convert.ToInt32(textBox6.Text);

    int nd = Convert.ToInt32(textBox5.Text);

    String sa = Convert.ToString(na, 2);

    String sb = Convert.ToString(nb, 2);

    String sc = Convert.ToString(nc, 2);

    String sd = Convert.ToString(nd, 2);

    int a = Convert.ToInt32(sa);

    int b = Convert.ToInt32(sb);

    int c = Convert.ToInt32(sc);

    int d = Convert.ToInt32(sd);

    int netMask = Convert.ToInt32(textBox13.Text);

    int numeroHosts = (int)(Math.Pow(2, (32-netMask))-2);

    int numeroSubRedes = (int)(Math.Pow(2, (netMask))-2);

    hosts.Text = "" + numeroHosts;

    subredes.Text = "" + numeroSubRedes;

    String ax = Convert.ToString(89, 2);

    // int ax = Convert.ToInt32( textBox8.Text, 2);

    // MessageBox.Show(" Numero en binario " +ax);

    textBox1.Text ="" +a;

    textBox2.Text ="" +b;

    textBox3.Text ="" +c;

    textBox4.Text ="" +d;

    if(a < 128)

    {

    textBox9.Text = "A";

    }

    if(a >= 128 && a < 192)

    {

    textBox9.Text = "B";

    }

    if(a >= 192 && a < 224)

    {

    textBox9.Text = "C";

    }

    if(a >= 224 && a < 240)

    {

    textBox9.Text = "D";

    }

    if(a >= 240&& a <= 255)

    {

    textBox9.Text = "E";

    }

    } // termina el if de validacion

    else

    {

    textBox7.Undo();

    }// termina else de validacion

    }// Termina if yaMostro

    }

    private void textBox6_TextChanged(object sender, System.EventArgs e)

    {

    if(yaMostro == true)

    {

    label5.Visible = true;

    label3.Visible = true;

    label6.Visible = true;

    textBox9.Visible = true;

    hosts.Visible = true;

    subredes.Visible = true;

    if( textBox6.Text != "")

    {

    int na = Convert.ToInt32(textBox8.Text);

    int nb = Convert.ToInt32(textBox7.Text);

    int nc = Convert.ToInt32(textBox6.Text);

    int nd = Convert.ToInt32(textBox5.Text);

    String sa = Convert.ToString(na, 2);

    String sb = Convert.ToString(nb, 2);

    String sc = Convert.ToString(nc, 2);

    String sd = Convert.ToString(nd, 2);

    int a = Convert.ToInt32(sa);

    int b = Convert.ToInt32(sb);

    int c = Convert.ToInt32(sc);

    int d = Convert.ToInt32(sd);

    int netMask = Convert.ToInt32(textBox13.Text);

    int numeroHosts = (int)(Math.Pow(2, (32-netMask))-2);

    int numeroSubRedes = (int)(Math.Pow(2, (netMask))-2);

    hosts.Text = "" + numeroHosts;

    subredes.Text = "" + numeroSubRedes;

    String ax = Convert.ToString(89, 2);

    // int ax = Convert.ToInt32( textBox8.Text, 2);

    // MessageBox.Show(" Numero en binario " +ax);

    textBox1.Text ="" +a;

    textBox2.Text ="" +b;

    textBox3.Text ="" +c;

    textBox4.Text ="" +d;

    if(a < 128)

    {

    textBox9.Text = "A";

    }

    if(a >= 128 && a < 192)

    {

    textBox9.Text = "B";

    }

    if(a >= 192 && a < 224)

    {

    textBox9.Text = "C";

    }

    if(a >= 224 && a < 240)

    {

    textBox9.Text = "D";

    }

    if(a >= 240&& a <= 255)

    {

    textBox9.Text = "E";

    }

    } // termina el if de validacion

    else

    {

    textBox6.Undo();

    }// termina else de validacion

    }// Termina if yaMostro

    }

    private void textBox5_TextChanged(object sender, System.EventArgs e)

    {

    if(yaMostro == true)

    {

    label5.Visible = true;

    label3.Visible = true;

    label6.Visible = true;

    textBox9.Visible = true;

    hosts.Visible = true;

    subredes.Visible = true;

    if( textBox5.Text != "")

    {

    int na = Convert.ToInt32(textBox8.Text);

    int nb = Convert.ToInt32(textBox7.Text);

    int nc = Convert.ToInt32(textBox6.Text);

    int nd = Convert.ToInt32(textBox5.Text);

    String sa = Convert.ToString(na, 2);

    String sb = Convert.ToString(nb, 2);

    String sc = Convert.ToString(nc, 2);

    String sd = Convert.ToString(nd, 2);

    int a = Convert.ToInt32(sa);

    int b = Convert.ToInt32(sb);

    int c = Convert.ToInt32(sc);

    int d = Convert.ToInt32(sd);

    int netMask = Convert.ToInt32(textBox13.Text);

    int numeroHosts = (int)(Math.Pow(2, (32-netMask))-2);

    int numeroSubRedes = (int)(Math.Pow(2, (netMask))-2);

    hosts.Text = "" + numeroHosts;

    subredes.Text = "" + numeroSubRedes;

    String ax = Convert.ToString(89, 2);

    // int ax = Convert.ToInt32( textBox8.Text, 2);

    // MessageBox.Show(" Numero en binario " +ax);

    textBox1.Text ="" +a;

    textBox2.Text ="" +b;

    textBox3.Text ="" +c;

    textBox4.Text ="" +d;

    if(a < 128)

    {

    textBox9.Text = "A";

    }

    if(a >= 128 && a < 192)

    {

    textBox9.Text = "B";

    }

    if(a >= 192 && a < 224)

    {

    textBox9.Text = "C";

    }

    if(a >= 224 && a < 240)

    {

    textBox9.Text = "D";

    }

    if(a >= 240&& a <= 255)

    {

    textBox9.Text = "E";

    }

    } // termina el if de validacion

    else

    {

    textBox5.Undo();

    }// termina else de validacion

    }// Termina if yaMostro

    }

    private void textBox13_TextChanged(object sender, System.EventArgs e)

    {

    if(textBox13.Text != "")

    {

    int netMask = 8;

    netMask = Convert.ToInt32(textBox13.Text);

    explicacion.Text = "";

    netMaskDecimal.Text = "";

    int i =0;

    if(netMask == 8) { netMaskDecimal.AppendText("255.0.0.0"); }

    if(netMask == 9) { netMaskDecimal.AppendText("255.128.0.0"); }

    if(netMask == 10) { netMaskDecimal.AppendText("255.192.0.0"); }

    if(netMask == 11) { netMaskDecimal.AppendText("255.224.0.0"); }

    if(netMask == 12) { netMaskDecimal.AppendText("255.240.0.0"); }

    if(netMask == 13) { netMaskDecimal.AppendText("255.248.0.0"); }

    if(netMask == 14) { netMaskDecimal.AppendText("255.252.0.0"); }

    if(netMask == 15) { netMaskDecimal.AppendText("255.254.0.0"); }

    if(netMask == 16) { netMaskDecimal.AppendText("255.255.0.0"); }

    if(netMask == 17) { netMaskDecimal.AppendText("255.255.128.0"); }

    if(netMask == 18) { netMaskDecimal.AppendText("255.255.192.0"); }

    if(netMask == 19) { netMaskDecimal.AppendText("255.255.224.0"); }

    if(netMask == 20) { netMaskDecimal.AppendText("255.255.240.0"); }

    if(netMask == 21) { netMaskDecimal.AppendText("255.255.248.0"); }

    if(netMask == 22) { netMaskDecimal.AppendText("255.255.252.0"); }

    if(netMask == 23) { netMaskDecimal.AppendText("255.255.254.0"); }

    if(netMask == 24) { netMaskDecimal.AppendText("255.255.255.0"); }

    if(netMask == 25) { netMaskDecimal.AppendText("255.255.255.128"); }

    if(netMask == 26) { netMaskDecimal.AppendText("255.255.255.192"); }

    if(netMask == 27) { netMaskDecimal.AppendText("255.255.255.224"); }

    if(netMask == 28) { netMaskDecimal.AppendText("255.255.255.240"); }

    if(netMask == 29) { netMaskDecimal.AppendText("255.255.255.248"); }

    if(netMask == 30) { netMaskDecimal.AppendText("255.255.255.252"); }

    if(netMask == 31) { netMaskDecimal.AppendText("255.255.255.254"); }

    if(netMask == 32) { netMaskDecimal.AppendText("255.255.255.255"); }

    int numeroHosts = (int)(Math.Pow(2, (32-netMask))-2);

    int numeroSubRedes = (int)(Math.Pow(2, (netMask))-2);

    hosts.Text = "" + numeroHosts;

    subredes.Text = "" + numeroSubRedes;

    for( i=0 ; i <netMask; i++)

    {

    if(i ==8 ||i== 16 || i== 24 || i == 32)

    {

    explicacion.AppendText(".");

    }

    explicacion.AppendText("1");

    }

    for(int x = i; x < (32); x++)

    {

    if(x ==8 || x == 16 ||x == 24 || x == 32 )

    {

    explicacion.AppendText(".");

    }

    explicacion.AppendText("0");

    }

    }

    }

    private void textBox1_TextChanged(object sender, System.EventArgs e)

    {

    try

    {

    if(yaMostro == true)

    {

    int netMask = Convert.ToInt32(textBox13.Text);

    explicacion.Text = "";

    netMaskDecimal.Text = "";

    int i =0;

    if(netMask == 8) { netMaskDecimal.AppendText("255.0.0.0"); }

    if(netMask == 9) { netMaskDecimal.AppendText("255.128.0.0"); }

    if(netMask == 10) { netMaskDecimal.AppendText("255.192.0.0"); }

    if(netMask == 11) { netMaskDecimal.AppendText("255.224.0.0"); }

    if(netMask == 12) { netMaskDecimal.AppendText("255.240.0.0"); }

    if(netMask == 13) { netMaskDecimal.AppendText("255.248.0.0"); }

    if(netMask == 14) { netMaskDecimal.AppendText("255.252.0.0"); }

    if(netMask == 15) { netMaskDecimal.AppendText("255.254.0.0"); }

    if(netMask == 16) { netMaskDecimal.AppendText("255.255.0.0"); }

    if(netMask == 17) { netMaskDecimal.AppendText("255.255.128.0"); }

    if(netMask == 18) { netMaskDecimal.AppendText("255.255.192.0"); }

    if(netMask == 19) { netMaskDecimal.AppendText("255.255.224.0"); }

    if(netMask == 20) { netMaskDecimal.AppendText("255.255.240.0"); }

    if(netMask == 21) { netMaskDecimal.AppendText("255.255.248.0"); }

    if(netMask == 22) { netMaskDecimal.AppendText("255.255.252.0"); }

    if(netMask == 23) { netMaskDecimal.AppendText("255.255.254.0"); }

    if(netMask == 24) { netMaskDecimal.AppendText("255.255.255.0"); }

    if(netMask == 25) { netMaskDecimal.AppendText("255.255.255.128"); }

    if(netMask == 26) { netMaskDecimal.AppendText("255.255.255.192"); }

    if(netMask == 27) { netMaskDecimal.AppendText("255.255.255.224"); }

    if(netMask == 28) { netMaskDecimal.AppendText("255.255.255.240"); }

    if(netMask == 29) { netMaskDecimal.AppendText("255.255.255.248"); }

    if(netMask == 30) { netMaskDecimal.AppendText("255.255.255.252"); }

    if(netMask == 31) { netMaskDecimal.AppendText("255.255.255.254"); }

    if(netMask == 32) { netMaskDecimal.AppendText("255.255.255.255"); }

    for( i=0 ; i <netMask; i++)

    {

    if(i ==8 ||i== 16 || i== 24 || i == 32)

    {

    explicacion.AppendText(".");

    }

    explicacion.AppendText("1");

    }

    for(int x = i; x < (32); x++)

    {

    if(x ==8 || x == 16 ||x == 24 || x == 32 )

    {

    explicacion.AppendText(".");

    }

    explicacion.AppendText("0");

    }

    yaMostro = true;

    label5.Visible = true;

    label3.Visible = true;

    label6.Visible = true;

    textBox9.Visible = true;

    hosts.Visible = true;

    subredes.Visible = true;

    if(textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox13.Text != "")

    {

    int a = Convert.ToInt32(textBox1.Text, 2);

    int b = Convert.ToInt32(textBox2.Text, 2);

    int c = Convert.ToInt32(textBox3.Text, 2);

    int d = Convert.ToInt32(textBox4.Text, 2);

    int numeroHosts = (int)(Math.Pow(2, (32-netMask))-2);

    int numeroSubRedes = (int)(Math.Pow(2, (netMask))-2);

    hosts.Text = "" + numeroHosts;

    subredes.Text = "" + numeroSubRedes;

    String ax = Convert.ToString(89, 2);

    // int ax = Convert.ToInt32( textBox8.Text, 2);

    // MessageBox.Show(" Numero en binario " +ax);

    textBox8.Text ="" +a;

    textBox7.Text ="" +b;

    textBox6.Text ="" +c;

    textBox5.Text ="" +d;

    if(a < 128)

    {

    textBox9.Text = "A";

    }

    if(a >= 128 && a < 192)

    {

    textBox9.Text = "B";

    }

    if(a >= 192 && a < 224)

    {

    textBox9.Text = "C";

    }

    if(a >= 224 && a <240)

    {

    textBox9.Text = "D";

    }

    if(a >= 240&& a <= 255)

    {

    textBox9.Text = "E";

    }

    } // termina el if de validacion

    else

    {

    textBox1.Undo();

    //MessageBox.Show("Falta introducir cierta información ", "Validación de captura - Calculadora de Redes - ITESM - CCM ", MessageBoxButtons.OK, MessageBoxIcon.Warning);

    }// termina else de validacion

    }// Terimna if ya mostro

    }

    catch(Exception ex){

    MessageBox.Show(" Error de captura binario es con valores de 1 y 0 \n" + "", "Error de captura" , MessageBoxButtons.OK, MessageBoxIcon.Warning);

    textBox1.Text = "0";

    }

    }

    private void textBox2_TextChanged(object sender, System.EventArgs e)

    {

    try

    {

    if(yaMostro == true)

    {

    int netMask = Convert.ToInt32(textBox13.Text);

    explicacion.Text = "";

    netMaskDecimal.Text = "";

    int i =0;

    if(netMask == 8) { netMaskDecimal.AppendText("255.0.0.0"); }

    if(netMask == 9) { netMaskDecimal.AppendText("255.128.0.0"); }

    if(netMask == 10) { netMaskDecimal.AppendText("255.192.0.0"); }

    if(netMask == 11) { netMaskDecimal.AppendText("255.224.0.0"); }

    if(netMask == 12) { netMaskDecimal.AppendText("255.240.0.0"); }

    if(netMask == 13) { netMaskDecimal.AppendText("255.248.0.0"); }

    if(netMask == 14) { netMaskDecimal.AppendText("255.252.0.0"); }

    if(netMask == 15) { netMaskDecimal.AppendText("255.254.0.0"); }

    if(netMask == 16) { netMaskDecimal.AppendText("255.255.0.0"); }

    if(netMask == 17) { netMaskDecimal.AppendText("255.255.128.0"); }

    if(netMask == 18) { netMaskDecimal.AppendText("255.255.192.0"); }

    if(netMask == 19) { netMaskDecimal.AppendText("255.255.224.0"); }

    if(netMask == 20) { netMaskDecimal.AppendText("255.255.240.0"); }

    if(netMask == 21) { netMaskDecimal.AppendText("255.255.248.0"); }

    if(netMask == 22) { netMaskDecimal.AppendText("255.255.252.0"); }

    if(netMask == 23) { netMaskDecimal.AppendText("255.255.254.0"); }

    if(netMask == 24) { netMaskDecimal.AppendText("255.255.255.0"); }

    if(netMask == 25) { netMaskDecimal.AppendText("255.255.255.128"); }

    if(netMask == 26) { netMaskDecimal.AppendText("255.255.255.192"); }

    if(netMask == 27) { netMaskDecimal.AppendText("255.255.255.224"); }

    if(netMask == 28) { netMaskDecimal.AppendText("255.255.255.240"); }

    if(netMask == 29) { netMaskDecimal.AppendText("255.255.255.248"); }

    if(netMask == 30) { netMaskDecimal.AppendText("255.255.255.252"); }

    if(netMask == 31) { netMaskDecimal.AppendText("255.255.255.254"); }

    if(netMask == 32) { netMaskDecimal.AppendText("255.255.255.255"); }

    for( i=0 ; i <netMask; i++)

    {

    if(i ==8 ||i== 16 || i== 24 || i == 32)

    {

    explicacion.AppendText(".");

    }

    explicacion.AppendText("1");

    }

    for(int x = i; x < (32); x++)

    {

    if(x ==8 || x == 16 ||x == 24 || x == 32 )

    {

    explicacion.AppendText(".");

    }

    explicacion.AppendText("0");

    }

    yaMostro = true;

    label5.Visible = true;

    label3.Visible = true;

    label6.Visible = true;

    textBox9.Visible = true;

    hosts.Visible = true;

    subredes.Visible = true;

    if(textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox13.Text != "")

    {

    int a = Convert.ToInt32(textBox1.Text, 2);

    int b