You are on page 1of 8

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace subnet_NIM
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)


{

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)


{
comboBox2.Items.Clear();
Object a;
String b;
a = comboBox1.SelectedItem;
b = a.ToString();

if (b == "A")
{

for (int i = 8; i <= 30; i++)


{
comboBox2.Items.Add(i);
}
}
else if (b == "B")
{
for (int i = 16; i <= 30; i++)
{
comboBox2.Items.Add(i);
}
}
else if (b == "C")
{
for (int i = 24; i <= 30; i++)
{
comboBox2.Items.Add(i);
}
}
}

private void button1_Click(object sender, EventArgs e)


{
double n = 0;
double h = 0;
double net = 0;
double host = 0;
String kelas = "";
String prefix = "";
Object a;
Object b;
String s = "";
a = comboBox1.SelectedItem;
b = comboBox2.SelectedItem;
kelas = a.ToString();
prefix = b.ToString();

if (kelas == "A")
{
if (prefix == "8")
{
n = 0;
h = 24;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.0.0.0";
}
else if (prefix == "9")
{
n = 1;
h = 23;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.128.0.0";
}
else if (prefix == "10")
{
n = 2;
h = 22;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.192.0.0";
}
else if (prefix == "11")
{
n = 3;
h = 21;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.224.0.0";
}
else if (prefix == "12")
{
n = 4;
h = 20;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.240.0.0";
}
else if (prefix == "13")
{
n = 5;
h = 19;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.248.0.0";
}
else if (prefix == "14")
{
n = 6;
h = 18;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.252.0.0";
}
else if (prefix == "15")
{
n = 7;
h = 17;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.254.0.0";
}
else if (prefix == "16")
{
n = 8;
h = 16;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.0.0";
}
else if (prefix == "17")
{
n = 9;
h = 15;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.128.0";
}
else if (prefix == "18")
{
n = 10;
h = 14;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.192.0";
}
else if (prefix == "19")
{
n = 11;
h = 13;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.224.0";
}
else if (prefix == "20")
{
n = 12;
h = 12;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.240.0";
}
else if (prefix == "21")
{
n = 13;
h = 11;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.248.0";
}
else if (prefix == "22")
{
n = 14;
h = 10;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.252.0";
}
else if (prefix == "23")
{
n = 15;
h = 9;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.254.0";
}
else if (prefix == "24")
{
n = 16;
h = 8;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.0";
}
else if (prefix == "25")
{
n = 17;
h = 7;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.128";
}
else if (prefix == "26")
{
n = 18;
h = 6;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.192";
}
else if (prefix == "27")
{
n = 19;
h = 5;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.224";
}
else if (prefix == "28")
{
n = 20;
h = 4;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.240";
}
else if (prefix == "29")
{
n = 21;
h = 3;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.248";
}
else if (prefix == "30")
{
n = 22;
h = 2;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.252";
}
}
else if (kelas == "B")
{
if (prefix == "16")
{
n = 0;
h = 16;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.0.0";
}
else if (prefix == "17")
{
n = 1;
h = 15;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.128.0";
}
else if (prefix == "18")
{
n = 2;
h = 14;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.192.0";
}
else if (prefix == "19")
{
n = 3;
h = 13;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.224.0";
}
else if (prefix == "20")
{
n = 4;
h = 12;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.240.0";
}
else if (prefix == "21")
{
n = 5;
h = 11;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.248.0";
}
else if (prefix == "22")
{
n = 6;
h = 10;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.252.0";
}
else if (prefix == "23")
{
n = 7;
h = 9;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.254.0";
}
else if (prefix == "24")
{
n = 8;
h = 8;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.0";
}
else if (prefix == "25")
{
n = 9;
h = 7;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.128";
}
else if (prefix == "26")
{
n = 10;
h = 6;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.192";
}
else if (prefix == "27")
{
n = 11;
h = 5;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.224";
}
else if (prefix == "28")
{
n = 12;
h = 4;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.240";
}
else if (prefix == "29")
{
n = 13;
h = 3;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.248";
}
else if (prefix == "30")
{
n = 14;
h = 2;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.252";
}

}
else if (kelas == "C")
{
if (prefix == "24")
{
n = 0;
h = 8;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.0";
}
else if (prefix == "25")
{
n = 1;
h = 7;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.128";
}
else if (prefix == "26")
{
n = 2;
h = 6;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.192";
}
else if (prefix == "27")
{
n = 3;
h = 5;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.224";
}
else if (prefix == "28")
{
n = 4;
h = 4;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.240";
}
else if (prefix == "29")
{
n = 5;
h = 3;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.248";
}
else if (prefix == "30")
{
n = 6;
h = 2;
net = Math.Pow(2, n);
host = ((Math.Pow(2, h)) - 2);
s = "255.255.255.252";
}
}

textBox1.Text = "" + net;


textBox2.Text = "" + host;
textBox3.Text = s;
}
}
}