コード例 #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));
 }
コード例 #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)));
 }
コード例 #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;
 }
コード例 #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);
 }
コード例 #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));
     }
 }
コード例 #6
0
 /// <summary>
 /// get binary notation for ip
 /// </summary>
 /// <returns>ip in binary notation</returns>
 public string GetBinaryNotaion()
 {
     return(SubnetUtils.IpToBinary(ToString()));
 }