如何判断IP地址是否正确

public bool IsIp(string ip)
        {
            bool b = true;
            string[] lines = new string[4];
            string s = ".";
            lines = ip.Split(s.ToCharArray(), 4);//分割字符串
            for (int i = 0; i < 4; i++)
            {
                if(Convert.ToInt32 (lines[i])>=255||Convert.ToInt32(lines[i])<0)
                {
                    b = false;
                    return b;
                }
            }
            return b;
        }

你可能感兴趣的:(C#,c#,IP)