zoukankan      html  css  js  c++  java
  • C#验证IP地址和端口

           ///<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;         }

    Any fool can write code that a computer can understand. Good programmers write code that humans can understand. –Martin Fowler
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    PIC18F2455/2550/4455/4550之通用串行总线USB
    今天,一个新的起点
    WM_COPYDATA消息
    图片浏览(附带样式+效果)
    这条路,走远一点,再远一点
    html之table(10种表格)
    数据导出成Excel
    .net 附件下载
    .net Repeater嵌套的数据绑定问题
    AjaxPro.2.dll的使用方法,以实例讲解。
  • 原文地址:https://www.cnblogs.com/gerryge/p/2869644.html
Copyright © 2011-2022 走看看