Exemplo n.º 1
0
 /// <summary>
 /// sonvert subnet mask to cidr
 /// </summary>
 /// <returns>CIDR value of subnet mask </returns>
 public string GetCIDRNotation()
 {
     if (subnet == null)
     {
         throw new NullReferenceException("No subnet mask provided for this IpAnalyzer Object");
     }
     return("/" + SubnetUtils.SubnetMaskToCIDR(subnet));
 }
Exemplo n.º 2
0
 /// <summary>
 /// calculate number of hosts for each subnet in this subnet mask
 /// </summary>
 /// <returns>max number of hosts</returns>
 public int GetNumberOfHosts()
 {
     if (subnet == null)
     {
         throw new NullReferenceException("No subnet mask provided for this IpAnalyzer Object");
     }
     return((int)Math.Pow(2, 32 - SubnetUtils.SubnetMaskToCIDR(subnet)));
 }
Exemplo n.º 3
0
 /// <summary>
 /// create new ip and subnet mask
 /// </summary>
 /// <param name="ip">ip</param>
 /// <param name="subnetMask">subnet mask</param>
 public IpAnalyzer(string ip, string subnetMask)
     : this(ip)
 {
     if (!SubnetUtils.IsValidSubnetMask(subnetMask))
     {
         throw new ArgumentException("Invalid subnet mask", "subnetMask");
     }
     subnet = subnetMask;
 }
Exemplo n.º 4
0
 /// <summary>
 /// create new ip and subnet mask
 /// </summary>
 /// <param name="ip">ip </param>
 /// <param name="cidr">subnet mask in cidr</param>
 public IpAnalyzer(string ip, int cidr)
     : this(ip)
 {
     if (!SubnetUtils.IsValidCIDR(cidr))
     {
         throw new ArgumentException("Invalid CIDR", "cidr");
     }
     subnet = SubnetUtils.CIDRToSubnetMask(cidr);
 }
Exemplo n.º 5
0
 /// <summary>
 /// calculate number of subnets for this subnet mask
 /// </summary>
 /// <returns>number of subnets</returns>
 public int GetNumberOfSubnets()
 {
     if (GetClass() == IpClass.A)
     {
         return((int)Math.Pow(2, SubnetUtils.SubnetMaskToCIDR(subnet) - 8));
     }
     else if (GetClass() == IpClass.B)
     {
         return((int)Math.Pow(2, SubnetUtils.SubnetMaskToCIDR(subnet) - 16));
     }
     else
     {
         return((int)Math.Pow(2, SubnetUtils.SubnetMaskToCIDR(subnet) - 24));
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// get binary notation for ip
 /// </summary>
 /// <returns>ip in binary notation</returns>
 public string GetBinaryNotaion()
 {
     return(SubnetUtils.IpToBinary(ToString()));
 }