判断ip地址是否合法

private bool TryIp(string ipaddress)
{
    string[] ip = new string[4];
    string s = ".";
    ip = ipaddress.Split(s.ToCharArray(), 4);
    if (ip.Length < 4)
    {
         return false;
    }
    for (int i = 0; i < 4; i++)
    {
        if (Convert.ToInt32(ip[i]) >= 255)
        {
            return false;
        }
    }
    return true;
}            

 

posted @ 2020-11-30 17:02  llkj  阅读(370)  评论(0编辑  收藏  举报