Пример #1
0
    static void Main(string[] args)
    {
        IPAddress ip1 = IPAddress.Parse("127.0.0.1");
        IPAddress ip2 = IPAddress.Parse("10.254.254.254");

        if (ip1.Compare(ip2) == 0)
        {
            Console.WriteLine("ip1 == ip2");
        }
        else if (ip1.Compare(ip2) == 1)
        {
            Console.WriteLine("ip1 > ip2");
        }
        else if (ip1.Compare(ip2) == -1)
        {
            Console.WriteLine("ip1 < ip2");
        }
    }
Пример #2
0
        public void incrementTest()
        {
            IPAddress ipAddress = new IPAddress(new byte[] { 0, 0, 0, 0 });
            int       i         = 0;

            while (true)
            {
                if (ipAddress.Compare(new IPAddress(new byte[] { 0, 0, 255, 255 })) == 1)
                {
                    break;
                }

                ipAddress.Increment();
                i++;
            }
            Assert.AreEqual(i, 256 * 256);
            //Assert.AreNotEqual(i, 0xFF_FF_FF_FF);
        }
Пример #3
0
        /// <summary>
        /// 实现控件输入检查的函数
        /// </summary>
        /// <returns></returns>
        public override bool CheckInput()
        {
            bool result = true;//默认是可以通过

            #region MyRegion
            if (this.txtName.Text.Trim().Length == 0)
            {
                MessageDxUtil.ShowWarning(Const.MsgCheckInput + lblName.Text.Replace(Const.MsgCheckSign, string.Empty));
                this.txtName.Focus();
                result = false;
            }
            else if (this.txtAuthorizeType.Text.Length == 0)
            {
                MessageDxUtil.ShowWarning(Const.MsgCheckInput + lblAuthorizeType.Text.Replace(Const.MsgCheckSign, string.Empty));
                this.txtAuthorizeType.Focus();
                result = false;
            }
            else if (this.txtIPStart.Text.Length == 0)
            {
                MessageDxUtil.ShowWarning(Const.MsgCheckInput + lblIPStart.Text.Replace(Const.MsgCheckSign, string.Empty));
                this.txtIPStart.Focus();
                result = false;
            }
            else if (this.txtIPEnd.Text.Length == 0)
            {
                MessageDxUtil.ShowWarning(Const.MsgCheckInput + lblIPEnd.Text.Replace(Const.MsgCheckSign, string.Empty));
                this.txtIPEnd.Focus();
                result = false;
            }

            IPAddress ip1 = IPAddress.Parse(this.txtIPStart.Text);
            IPAddress ip2 = IPAddress.Parse(this.txtIPEnd.Text);

            if (ip1.Compare(ip2) == 1)
            {
                MessageDxUtil.ShowTips("请IP开始地址不能大于结束地址, 请修改");
                this.txtIPEnd.Focus();
                result = false;
            }

            #endregion

            return(result);
        }
Пример #4
0
        public static List <IPAddress> GetContinousAddressesInRange(IPAddress startAddress, IPAddress endAddress)
        {
            var       result = new List <IPAddress>();
            IPAddress end;
            IPAddress start;

            if (startAddress.Compare(endAddress) < 0)
            {
                start = startAddress;
                end   = endAddress;
            }
            else
            {
                end   = startAddress;
                start = endAddress;
            }

            while (start.Compare(end) <= 0)
            {
                result.Add(start);
                start = start.Add(1);
            }
            return(result);
        }
Пример #5
0
 public static bool IsInRange(IPAddress address, IPAddress startAddress, IPAddress endAddress)
 {
     return(address.Compare(startAddress) >= 0 &&
            address.Compare(endAddress) <= 0);
 }
Пример #6
0
 public static bool GreaterOrEqualTo(this IPAddress ip1, IPAddress ip2)
 {
     return(ip1.Compare(ip2) >= 0);
 }
Пример #7
0
 public static bool LessOrEqualTo(this IPAddress ip1, IPAddress ip2)
 {
     return(ip1.Compare(ip2) <= 0);
 }