码迷,mamicode.com
首页 > 其他好文 > 详细

ip范围生成

时间:2014-09-03 19:41:07      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:blog   os   io   ar   for   art   div   sp   log   

 

--测试  ,,大家还有什么更好的方法

List<string> list = new List<string>();
// new ConsoleApplicationTest.Test1.class33().NewMethod(list,"192.168.1.2","192.168.1.23"); 后1 !=
// new ConsoleApplicationTest.Test1.class33().NewMethod(list, "192.168.1.2", "192.168.3.23");后2 !=
// new ConsoleApplicationTest.Test1.class33().NewMethod(list, "192.138.1.2", "192.168.3.23"); //后3 !=
// new ConsoleApplicationTest.Test1.class33().NewMethod(list, "122.168.1.2", "192.168.3.23");//后4 !=

// new ConsoleApplicationTest.Test1.class33().NewMethod(list, "122.168.1.2", "124.168.1.2");

// new ConsoleApplicationTest.Test1.class33().NewMethod(list, "124.158.1.2", "124.168.1.2");


public class class33 { public List<string> NewMethod(List<string> list, string p1, string p2) { string start = p1;// item.Attributes["start"].Value; string end = p2;// item.Attributes["end"].Value; string[] sp1 = start.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); string[] sp2 = end.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); if (sp1[0] == sp2[0]) { if (sp1[1] == sp2[1]) { if (sp1[2] == sp2[2]) { if (sp1[3] == sp2[3]) { if (!list.Contains(start)) { list.Add(start); } } else { #region 3 != int _start = Convert.ToInt16(sp1[3]); int _end = Convert.ToInt16(sp2[3]); for (int j = _start; j <= _end; j++) { if (!list.Contains(sp1[0] + "." + sp1[1] + "." + sp1[2] + "." + j.ToString())) { list.Add(sp1[0] + "." + sp1[1] + "." + sp1[2] + "." + j.ToString()); } } #endregion }//3 } else { #region 2 != int _start = 0; int _end = 0; _start = Convert.ToInt16(sp1[2]); _end = Convert.ToInt16(sp2[2]); for (int j = _start; j <= _end; j++) { if (!list.Contains(sp1[0] + "." + sp1[1] + "." + j.ToString() + "." + sp1[3])) { list.Add(sp1[0] + "." + sp1[1] + "." + j.ToString() + "." + sp1[3]); } string t1 = sp1[0] + "." + sp1[1] + "." + j.ToString() + "." + sp1[3]; string t2 = sp2[0] + "." + sp2[1] + "." + j.ToString() + "." + sp2[3]; if (t1 != t2) { NewMethod(list, t1, t2); } } #endregion }//2 } else { #region 1 != int _start = 0; int _end = 0; _start = Convert.ToInt16(sp1[1]); _end = Convert.ToInt16(sp2[1]); for (int j = _start; j <= _end; j++) { if (!list.Contains(sp1[0] + "." + j.ToString() + "." + sp1[2] + "." + sp1[3])) { list.Add(sp1[0] + "." + j.ToString() + "." + sp1[2] + "." + sp1[3]); } string t1 = sp1[0] + "." + j.ToString() + "." + sp1[2] + "." + sp1[3]; string t2 = sp2[0] + "." + j.ToString() + "." + sp2[2] + "." + sp2[3]; if (t1 != t2) { list = NewMethod(list, t1, t2); } } #endregion }//1 } else { #region 0!= int _start = 0; int _end = 0; _start = Convert.ToInt16(sp1[0]); _end = Convert.ToInt16(sp2[0]); for (int j = _start; j <= _end; j++) { if (!list.Contains(j.ToString() + "." + sp1[1] + "." + sp1[2] + "." + sp1[3])) { list.Add(j.ToString() + "." + sp1[1] + "." + sp1[2] + "." + sp1[3]); } string t1 = j.ToString() + "." + sp1[1] + "." + sp1[2] + "." + sp1[3]; string t2 = j.ToString() + "." + sp2[1] + "." + sp2[2] + "." + sp2[3]; if (t1 != t2) { list = NewMethod(list, t1, t2); } } #endregion }//0 return list; } }

  

ip范围生成

标签:blog   os   io   ar   for   art   div   sp   log   

原文地址:http://www.cnblogs.com/window5549-accp/p/3954287.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!