判断IP地址是否合法类

时间:2022-12-13 15:04:44
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[];
string s = ".";
lines = ip.Split(s.ToCharArray(), );//分隔字符串
try
{
for (int i = ; i < ; i++)
{
if (Convert.ToInt32(lines[i]) >= || Convert.ToInt32(lines[i]) < )
{
b = false;
return b;
}
}
return b;
}
catch { return false; }
}
}
}