Ejemplo n.º 1
0
 public static bool IsSubnet(IpAddress _ip, int _maskBitsNum)
 {
     if (_ip.GetSubnetAddress(IpAddress.BuildMaskFromBits(_maskBitsNum)).CompareTo(_ip) != 0)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 根据子网地址和掩码位数初始化子网类
 /// </summary>
 /// <param name="_ip">子网地址</param>
 /// <param name="_maskBitsNum">掩码位数</param>
 public Subnet(IpAddress _ip, int _maskBitsNum)
 {
     mask = IpAddress.BuildMaskFromBits(_maskBitsNum);
     if (_ip.GetSubnetAddress(mask).CompareTo(_ip) != 0)
     {
         throw new SubnetErrorException("子网地址和掩码不搭配");
     }
     ip = _ip;
 }