判断IP地址是否合法类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IPFlag
{
    public class Class1
    {
        public bool ISIP(string ip)
        {
            bool b = true;
            string[] lines = new string[4];
            string s = ".";
            lines = ip.Split(s.ToCharArray(), 4);//分隔字符串
            try
            {
                for (int i = 0; i < 4; i++)
                {
                    if (Convert.ToInt32(lines[i]) >= 255 || Convert.ToInt32(lines[i]) < 0)
                    {
                        b = false;
                        return b;
                    }
                }
                return b;
            }
            catch { return false; }
        }
    }
}
原文地址:https://www.cnblogs.com/rogge7/p/5385834.html