private static void Main(string[] args) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Console.WriteLine("QQWry Sample!"); var config = new QQWryOptions() { DbPath = MapRootPath("~/IP/qqwry.dat") }; #region QQWry Console.WriteLine(""); Console.WriteLine("QQWry"); var ipSearch = new QQWryIpSearch(config); var copyWrite = ipSearch.GetCopyWrite(); var date = copyWrite.Text.Replace("纯真IP地址数据库 ", string.Empty); var getNewDb = ipSearch.Version.IndexOf(date) == -1; ipSearch.Init(getNewDb); ipSearch.GetIpLocation("52.202.142.95"); for (var i = 0; i < 100; i++) { var ipLocation = ipSearch.GetIpLocation(GetRandomIp(ipSearch)); Write(ipLocation); } Console.WriteLine("记录总数" + ipSearch.IpCount); Console.WriteLine("版本" + ipSearch.Version); #endregion #region QQWry.DependencyInjection Console.WriteLine(""); Console.WriteLine("QQWry.DependencyInjection"); var service = new ServiceCollection(); service.AddQQWry(config); var serviceProvider = service.BuildServiceProvider(); using (var scope = serviceProvider.CreateScope()) { var ipSearchInterface = scope.ServiceProvider.GetRequiredService <IIpSearch>(); for (var i = 0; i < 100; i++) { var ipLocation = ipSearch.GetIpLocation(GetRandomIp(ipSearch)); Write(ipLocation); } Console.WriteLine("记录总数" + ipSearchInterface.IpCount); Console.WriteLine("版本" + ipSearchInterface.Version); } #endregion #region java to QQWry Console.WriteLine(""); Console.WriteLine("java to QQWry"); var qqWry = new Java2QQWry(config.DbPath); for (var i = 0; i < 100; i++) { var ip = GetRandomIp(ipSearch); var ipLocation = qqWry.SearchIPLocation(ip); Write(ip, ipLocation); } #endregion Console.ReadKey(); }
private static void Main(string[] args) { Console.WriteLine("QQWry Sample!"); var config = new QQWryOptions() { DbPath = Test.MapRootPath("qqwry.dat") }; #region QQWry Console.WriteLine(""); Console.WriteLine("QQWry"); var ipSearch = new QQWryIpSearch(config); var ipSearchMode2 = new QQWryIpSearchMode2(config); var copyWrite = ipSearch.GetCopyWrite(); var date = copyWrite.Text.Replace("纯真IP地址数据库 ", string.Empty); var getNewDb = ipSearch.Version.IndexOf(date) == -1; ipSearch.Init(getNewDb); ipSearchMode2.Init(getNewDb); for (var i = 0; i < 100; i++) { var ipLocation = ipSearchMode2.GetIpLocation(Test.GetRandomIp(ipSearchMode2)); Write(ipLocation); } Console.WriteLine("记录总数" + ipSearchMode2.IpCount); Console.WriteLine("版本" + ipSearchMode2.Version); #endregion #region QQWry.DependencyInjection Console.WriteLine(""); Console.WriteLine("QQWry.DependencyInjection"); var service = new ServiceCollection(); service.AddQQWry(config); var serviceProvider = service.BuildServiceProvider(); using (var scope = serviceProvider.CreateScope()) { var ipSearchInterface = scope.ServiceProvider.GetRequiredService <IIpSearch>(); for (var i = 0; i < 100; i++) { var ipLocation = ipSearch.GetIpLocation(Test.GetRandomIp(ipSearch)); Write(ipLocation); } Console.WriteLine("记录总数" + ipSearchInterface.IpCount); Console.WriteLine("版本" + ipSearchInterface.Version); } #endregion #region java to QQWry Console.WriteLine(""); Console.WriteLine("java to QQWry"); var javaQQWry = new Java2QQWry(config.DbPath); for (var i = 0; i < 100; i++) { var ip = Test.GetRandomIp(ipSearch); var ipLocation = javaQQWry.SearchIPLocation(ip); Write(ip, ipLocation); } #endregion var summary = BenchmarkRunner.Run <Test>(); Console.ReadKey(); }