public static bool isLAN(IPAddress ip) { if (_SegIPList_LAN == null) { _SegIPList_LAN = new SegmentIPOrderList(); string[] netmasks = new string[] { "0.0.0.0/8", "10.0.0.0/8", //"100.64.0.0/10", //部分地区运营商貌似在使用这个,这个可能不安全 "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12", //"192.0.0.0/24", //"192.0.2.0/24", "192.168.0.0/16", //"198.18.0.0/15", //"198.51.100.0/24", //"203.0.113.0/24", }; netmasks.ToList().ForEach(s => _SegIPList_LAN.Add(new SegmentIP(s))); } var rst = _SegIPList_LAN.IsInList(ip); return(rst); }
public void TestIPRangeQuery_new() { SegmentIPOrderList iprs = new SegmentIPOrderList(); iprs.LoadChinaIP(); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 100000; i++) { { var rst = iprs.IsInList(IPAddress.Parse("203.57.200.1")); Assert.IsTrue(rst); } { var rst = iprs.IsInList(IPAddress.Parse("202.0.184.1")); Assert.IsFalse(rst); } } sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); }