public void QueryTest() { QQWryLocator _qqWry = new QQWryLocator(@"D:\OneDrive\软件\开发\qqwry\qqwry.dat"); IPLocation _ip = _qqWry.Query("116.226.81.32"); Assert.AreEqual("上海市 电信", string.Format("{0} {1}", _ip.Country, _ip.Local)); }
[AsyncTimeout(30000)]// 超时时间30秒钟 public void IndexAsync(long?JournalID) { IAccessLogService logService = ServiceContainer.Instance.Container.Resolve <IAccessLogService>(); HttpBrowserCapabilitiesBase bc = HttpContext.Request.Browser; AccessLog stat = new AccessLog(); stat.JournalID = JournalID == null ? 0 : JournalID.Value; stat.Browser = bc.Browser; stat.BrowserType = bc.Type; stat.Version = bc.Version; stat.Platform = bc.Platform; stat.UrlReferrer = HttpContext.Request.UrlReferrer == null ? "" : HttpContext.Request.UrlReferrer.ToString(); stat.UserHostAddress = Utils.GetRealIP(); stat.HttpMethod = HttpContext.Request.HttpMethod; stat.IsAuthenticated = HttpContext.Request.IsAuthenticated; stat.LogDateTime = DateTime.Now.ToLocalTime(); try { QQWryLocator ipLocator = new QQWryLocator(); IPLocation ipInfo = ipLocator.Query(stat.UserHostAddress); stat.Country = ipInfo.Country; stat.City = ipInfo.Local; logService.AddAccessLog(stat); //参数要放在这个字典里面实现向Completed action传递 //AsyncManager.Parameters["ExecResult"] = "<script> var result = 'success';</script>"; } catch (Exception ex) { LogProvider.Instance.Error("访问日志统计:" + ex.Message); //AsyncManager.Parameters["ExecResult"] = "error:" + ex.Message; } AsyncManager.OutstandingOperations.Decrement(); }
private static void Main(string[] args) { try { QQWryLocator qqWry = new QQWryLocator(@"D:\QQWry.Dat"); //初始化数据库文件,并获得IP记录数,通过Count可以获得 IPLocation ip = qqWry.Query("222.71.108.200"); //查询一个IP地址 Console.WriteLine("{0} {1} {2}", ip.IP, ip.Country, ip.Local); Stopwatch stopwatch = new Stopwatch(); List <string> ips = new List <string> { "218.5.3.128", "120.67.217.7", "125.78.67.175", "220.250.64.23", "218.5.3.128", "120.67.217.7", "125.78.67.175", "220.250.64.23" }; stopwatch.Start(); for (int i = 0; i < 100; i++) { foreach (string item in ips) { ip = qqWry.Query(item); Console.WriteLine("{0} {1} {2}", ip.IP, ip.Country, ip.Local); } } stopwatch.Stop(); Console.WriteLine("查询了800次IP,QQWryLocator 花了{0} ms", stopwatch.ElapsedMilliseconds); } catch (Exception e) { Console.WriteLine(e.Message); } Console.Read(); }
/// <summary> /// /// </summary> /// <param name="ip"></param> public static string GetIpCity(string dbPath, string strIp) { QQWryLocator qqWry = new QQWryLocator(dbPath); //初始化数据库文件,并获得IP记录数,通过Count可以获得 IPLocation ip = qqWry.Query(strIp); //查询一个IP地址 return(ip.Country.Trim()); //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); //stopwatch.Stop(); //Console.WriteLine("一共花了{0} ms的时间", stopwatch.ElapsedMilliseconds); }
public void LoadIPData(string fileName) { if (File.Exists(fileName) == false) { return; } try { qqWry = new QQWryLocator(fileName); } catch { qqWry = null; } }
static void Main(string[] args) { var options = new Option(); /* * PARSER OPTIONS */ // Parser options via CommandLinePaser if (CommandLine.Parser.Default.ParseArguments(args, options)) { Timeout = options.Timeout * 1000; Interval = options.Interval * 1000; MaxHop = options.MaxHop; EnableASN = options.EnableASN; UseIPIPGeo = options.UseIPIPGeo; DomainCheck = options.DomainCheck; } else { return; // if invalid option, end application } // Timeout or Interval MUST greater than 0 if (Timeout == 0 || Interval == 0) { Console.WriteLine(options.GetUsage()); return; } /* * DOMAIN OR IP PROCCESS */ // Parser the first parameter is IP or Domain if (args.Count() <= 0) // LESS ONE PARAMETER { Console.WriteLine(options.GetUsage()); return; } else if (!(ConsoleHelper.IsValidIPAddress(args[0]) || // IS IP ADDRESS ConsoleHelper.IsValidDomainName(args[0]) // OR DOMAIN )) { Console.WriteLine("ERROR: {0} is unknown IP address or domain.\n", args[0]); Console.WriteLine(options.GetUsage()); return; } // save hostname NTR_HOSTNAME = args[0]; // resolving ip address string NTR_DESTIPADDR; if (ConsoleHelper.IsValidDomainName(NTR_HOSTNAME)) { try { NTR_DESTIPADDR = Dns.GetHostAddresses(NTR_HOSTNAME)[0].ToString(); } catch { Console.WriteLine($"ERROR: cannot resolve domain '{NTR_HOSTNAME}' to IP address!\n"); return; } } else { NTR_DESTIPADDR = NTR_HOSTNAME; } // is ipv6 or ipv4 ipv6 = ConsoleHelper.IsIPv6(NTR_DESTIPADDR); /* * INITIZATION */ // to load ip location database when ipv4 only if (ipv6 == false) { try { QQWry = new QQWryLocator(AppDomain.CurrentDomain.BaseDirectory + "\\qqwry.dat"); } catch { } } // SetUp ASN Paser AsnHelper.BgpQueryServer = BgpQueryServer; // SetUp Tracer var NtrResult = new NtrResultItem[MaxHop]; Trace.Timeout = Timeout; Trace.HostName = NTR_DESTIPADDR; // Create a new List used to store results for (int i = 0; i < MaxHop; i++) { NtrResultList.Add(new NtrResultItem()); } // Route Tracer Timer System.Timers.Timer TracerTimer = new System.Timers.Timer(); TracerTimer.Elapsed += new ElapsedEventHandler(Tracer); TracerTimer.Interval = Interval; TracerTimer.Enabled = true; // Display Timer System.Timers.Timer DisplayTimer = new System.Timers.Timer(); DisplayTimer.Elapsed += new ElapsedEventHandler(Display); DisplayTimer.Interval = Interval; DisplayTimer.Enabled = true; //Console.ReadLine(); Console.ReadKey(); }
public static void MyClassInitialize(TestContext testContext) { QQWryLocator.SetDefaultData(File.ReadAllBytes("Resources\\qqwry.dat")); }
public void LoadIPData(string fileName) { if (File.Exists(fileName) == false) return; try { qqWry = new QQWryLocator(fileName); } catch { qqWry = null; } }
/// <summary> /// QQ 根据ip获取地理位置 /// </summary> /// <param name="ip">ip</param> /// <returns></returns> public static IPLocation QQGetAddress(string ip) { QQWryLocator qqwry = new QQWryLocator(Converter.GetMapPath("qqwry.dat")); return(qqwry.Query(ip)); }