ip範囲生成

6110 ワード


--テスト、皆さんはもっと良い方法がありますか?
List list = new List();//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; } }