///<summary>        

/// 判断是否是Ip地址        

/// </summary>        

/// <param name="str1"></param>        

/// <returns></returns>

        public static bool IsIPAddress(string ip)         {

            if (string.IsNullOrEmpty(ip) || ip.Length < 7 || ip.Length > 15) return false;

            string regformat = @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$";

            Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);

            return regex.IsMatch(ip);

        }

 

 public static bool IsIPPort(string port)        

{            

bool isPort = false;            

int portNum;            

isPort = Int32.TryParse(port, out portNum);            

if (isPort && portNum >= 0 && portNum <= 65535)            

{                

isPort = true;            

}            

else            

{                

isPort = false;            

}

            return isPort;         }

相关文章:

  • 2022-12-23
  • 2021-07-17
  • 2021-12-14
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
猜你喜欢
  • 2021-04-22
  • 2021-11-23
  • 2021-09-16
  • 2022-01-14
  • 2021-06-20
  • 2022-12-23
  • 2021-06-02
相关资源
相似解决方案