Try a subnet mask: 0.0.0.0 128.0.0.0 192.0.0.0 224.0.0.0 240.0.0.0 248.0.0.0 252.0.0.0 254.0.0.0 255.0.0.0 255.128.0.0 255.192.0.0 255.224.0.0 255.240.0.0 255.248.0.0 255.252.0.0 255.254.0.0 255.255.0.0 255.255.128.0 255.255.192.0 255.255.224.0 255.255.240.0 255.255.248.0 255.255.252.0 255.255.254.0 255.255.255.0 255.255.255.128 255.255.255.192 255.255.255.224 255.255.255.240 255.255.255.248 255.255.255.252 255.255.255.254 255.255.255.255
Enter IP Address:
Enter Subnet mask:
Max subnets:
Max hosts/subnet:
IP Class:
using System; class MainClass { public static void Main (string[] args) { string tbMaxSubnets="", tbMaxHostsPerSubnet="", tbIPIn=""; string cl=""; // define as "Class A" if you want a Class A address range string ip="192.168.0.1"; string subnet="255.255.255.224"; string subnetbits = tosubnetCount(subnet); int max_subnets = 0; int max_hosts = 0; // int subnetbits = 0; string ip1 = ip; if (getClass(ip1) == "A" || cl.StartsWith("Class A")) { max_subnets = ((int)Math.Pow(2, System.Convert.ToInt32(subnetbits) - 8)) - 2; max_hosts = (int)Math.Pow(2, 32 - System.Convert.ToInt32(subnetbits)) - 2; tbMaxSubnets = Convert.ToString(max_subnets); } else if (getClass(ip1) == "B" || cl.StartsWith("Class B")) { max_hosts = (int)Math.Pow(2, 32 - System.Convert.ToInt32(subnetbits)) - 2; max_subnets = ((int)Math.Pow(2, System.Convert.ToInt32(subnetbits) - 16)) - 2; } else { max_hosts = (int)Math.Pow(2, 32 - System.Convert.ToInt32(subnetbits)) - 2; max_subnets = ((int)Math.Pow(2, System.Convert.ToInt32(subnetbits) - 24)) - 2; } if (max_subnets < 0) max_subnets = 0; tbMaxSubnets = Convert.ToString(max_subnets); tbMaxHostsPerSubnet = Convert.ToString(max_hosts); Console.WriteLine("Address class: {0}",getClass(ip1)); Console.WriteLine("Max subnets: {0}",tbMaxSubnets); Console.WriteLine("Max hosts per subnet: {0}",tbMaxHostsPerSubnet); } public static string tosubnetCount(string val) { switch (val) { case "0.0.0.0": return ("0"); case "128.0.0": return ("1"); case "192.0.0.0": return ("2"); case "224.0.0.0": return ("3"); case "240.0.0.0": return ("4"); case "248.0.0.0": return ("5"); case "252.0.0.0": return ("6"); case "254.0.0.0": return ("7"); case "255.0.0.0": return ("8"); case "255.128.0.0": return ("9"); case "255.192.0.0": return ("10"); case "255.224.0.0": return ("11"); case "255.240.0.0": return ("12"); case "255.248.0.0": return ("13"); case "255.252.0.0": return ("14"); case "255.254.0.0": return ("15"); case "255.255.0.0": return ("16"); case "255.255.128.0": return ("17"); case "255.255.192.0": return ("18"); case "255.255.224.0": return ("19"); case "255.255.240.0": return ("20"); case "255.255.248.0": return ("21"); case "255.255.252.0": return ("22"); case "255.255.254.0": return ("23"); case "255.255.255.0": return ("24"); case "255.255.255.128": return ("25"); case "255.255.255.192": return ("26"); case "255.255.255.224": return ("27"); case "255.255.255.240": return ("28"); case "255.255.255.248": return ("29"); case "255.255.255.252": return ("30"); case "255.255.255.254": return ("31"); case "255.255.255.255": return ("32"); default: return ("N/A"); } } public static string getClass(string ip) { if (ip == null) return (""); if (ip == "") return (""); string[] s = ip.Split('.'); if (System.Convert.ToInt32(s[0]) < 127) return ("A"); else if (System.Convert.ToInt32(s[0]) < 192) return ("B"); else if (System.Convert.ToInt32(s[0]) < 224) return ("C"); else if (System.Convert.ToInt32(s[0]) < 240) return ("D"); else if (System.Convert.ToInt32(s[0]) < 254) return ("E"); return ("Cannot determine"); } }