zoukankan      html  css  js  c++  java
  • ip范围生成 C#

    #region ip
    /// <summary>
    /// ip rang ,ip
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    bool Get_IPRangExist(string str, string ip)
    {
    bool val = false;
    if (string.IsNullOrEmpty(str))
    {
    return val;
    }
    if (str.Contains(ip))
    {
    return true;
    }
    string[] sp = str.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
    if (sp.Length > 0)
    {
    foreach (var item in sp)
    {

    if (item.Contains("-"))
    {
    string[] sp2 = item.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
    if (sp2.Length == 2)
    {
    val = GetIPInfo2(sp2[0], sp2[1], ip);
    if (val)
    {
    break;
    }
    }
    }
    else if (item.Contains("*")) {
    string[] spsynctlist = item.Split(new string[]{"*"},StringSplitOptions.RemoveEmptyEntries);
    foreach (var item_sp in spsynctlist)
    {
    if (ip.Contains(item_sp))
    {
    val = true; break;
    }

    }

    }
    if(item == ip)
    {
    val = true; break;
    }
    }
    }
    return val;
    }


    bool GetIPInfo2(string source, string des, string ip)
    {
    bool B_flag = false;
    if (source == des)
    {
    return source == ip;
    }


    string[] p1 = source.Split(new char[] { '.' });
    string[] p2 = des.Split(new char[] { '.' });
    List<Tuple<int,int>> tupeIPList=new System.Collections.Generic.List<Tuple<int,int>>();

    for (int i = 0; i < 4; i++)
    {
    string a = p1[i];string b = p2[i];
    int start = Math.Min(int.Parse(a), int.Parse(b));
    int end = Math.Max(int.Parse(a), int.Parse(b));
    tupeIPList.Add(new Tuple<int, int>(start, end));
    }
    #region MyRegion
    for (int a =tupeIPList[0].Item1; a <= tupeIPList[0].Item2; a++)
    {
    for (int b =tupeIPList[1].Item1; b <= tupeIPList[1].Item2; b++)
    {
    for (int c = tupeIPList[2].Item1; c <= tupeIPList[2].Item2; c++)
    {
    for (int d = tupeIPList[3].Item1; d <= tupeIPList[3].Item2;d++)
    {
    string template = string.Format("{0}.{1}.{2}.{3}",a,b,c,d);
    if (template==ip)
    {
    B_flag = true;
    break;
    }
    }
    }
    }
    }
    #endregion
    return B_flag;

    }


    #endregion
    public void test() {
    Console.WriteLine("start");
    List<Tuple<string, string>> a = new List<Tuple<string, string>>();
    a.Add(new Tuple<string, string>("10.0.0.0-10.255.255.255", "10.19.48.27"));
    a.Add(new Tuple<string, string>("10.*.*.*", "10.19.48.27"));
    a.Add(new Tuple<string, string>("10.1.25.13-10.255.25.13", "10.19.48.27"));
    a.Add(new Tuple<string, string>("10.1.25.13-10.255.25.13", "10.19.25.13"));
    foreach (var item in a)
    {
    var start1 = System.Diagnostics.Stopwatch.StartNew(); start1.Start();
    Console.WriteLine(Get_IPRangExist(item.Item1,item.Item2));
    start1.Stop();
    Console.WriteLine(item.Item1+" "+item.Item2+" ------- "+start1.ElapsedMilliseconds.ToString());
    }
    }

  • 相关阅读:
    微信扫码支付模式一和模式二的区别
    spring boot MongoDB的集成和使用
    Java 8 中的 Streams API 详解
    大并发量的订单的解析
    Springboot项目打成war包,部署到tomcat上,正常启动访问报错404
    最详细的虚拟机安装centos7教程
    nginx限制上传大小和超时时间设置说明/php限制上传大小
    一级域名和二级域名的区别是什么?分别有什么作用?
    快递物流查询接口介绍
    java 使用volatile实现线程数据的共享
  • 原文地址:https://www.cnblogs.com/window5549-accp/p/3954287.html
Copyright © 2011-2022 走看看