public void Index() { M.MemberInfo member = M.MemberInfo.GetByModify(DataSource, User.Identity.Id); DateTime begin = (DateTime)Types.GetDefaultValue(TType <DateTime> .Type); if (member.Birthday < begin) { member.Birthday = begin; } int location = member.County; if (location == 0) { City city; using (IPArea area = new IPArea()) { IPLocation local = area.Search(ClientIp); using (Country country = Country.GetCountry()) city = local.GetCity(country); } location = city != null ? city.Id : 441900; } this["Location"] = location; this["Member"] = member; Render("memberinfo.html"); }
public void SetAddress(int id = 0) { string target = Request.QueryString["target"]; if (string.IsNullOrEmpty(target)) { if (Request.UrlReferrer != null) { target = Request.UrlReferrer.ToString(); } } M.ShippingAddress address = M.ShippingAddress.GetById(DataSource, id, User.Identity.Id); int location; if (address == null) { City city; using (IPArea area = new IPArea()) { IPLocation local = area.Search(ClientIp); using (Country country = Country.GetCountry()) city = local.GetCity(country); } location = city != null ? city.Id : 441900; } else { location = address.County; } this["Target"] = target; this["Location"] = location; this["Address"] = address; Render("set_address.html"); }
public int FindIPAreaIndex(IPArea[] ipDb, int start, int end, long ipValue) { int result = -1; int loopTimes = 0; if (ipDb == null || start >= ipDb.Length || end >= ipDb.Length || end < start) { return(result); } int distance = end - start, pos = start, offset = start; IPArea ipInfo = null; while (distance >= 0) { if (distance % 2 == 0) { offset = distance / 2; } else { offset = (distance + 1) / 2; } ipInfo = ipDb[pos + offset]; if (ipInfo != null && (ipInfo.StartIP == ipValue || (ipInfo.StartIP < ipValue && ipValue <= ipInfo.EndIP))) { return(pos + offset); } if (ipValue < ipInfo.StartIP) { end = pos + offset - 1; distance = end - pos; } else { pos = pos + offset + 1; distance = end - pos; } loopTimes++; } // 往前找,尝试找到一个宽的ip段 pos = pos + offset - 1; while (pos >= 0) { ipInfo = ipDb[pos]; if (ipInfo != null && (ipInfo.StartIP == ipValue || (ipInfo.StartIP < ipValue && ipValue <= ipInfo.EndIP))) { return(pos); } pos--; } return(result); }
public void Index() { City city; using (IPArea area = new IPArea()) { IPLocation local = area.Search(ClientIp); using (Country country = Country.GetCountry()) city = local.GetCity(country); } this["Location"] = city != null ? city.Id : 441900; Render("shippingaddress.html"); }
public IPArea FindFirstIPAreaInfo(long ipValue) { IPArea result = null; IPArea[] ipDb = GetIPDBFromHttpContext(); if (ipDb == null || ipDb.Length < 1) { return(result); } int idx = FindIPAreaIndex(ipDb, ipValue); if (idx >= 0 && idx < ipDb.Length) { result = ipDb[idx]; } return(result); }
public void Welcome() { if (CheckRight()) { if (User != null && User.Identity.IsAuthenticated && User.Identity.IsAdmin) { if (CheckPost("welcome", () => { StringBuilder sb = new StringBuilder(); List <ModuleInfo> list = ModuleInfo.GetAllList(Context); foreach (ModuleInfo info in list) { sb.Append("<li><i class=\"dll\">"); sb.Append(info.Name); sb.Append("</i><i class=\"ii\"> v</i><i class=\"ver\">"); sb.Append(info.Version); sb.Append("</i><i class=\"up\"></i></li>"); } this["Version"] = sb.ToString(); string loginArea = User.Identity.LastIp; using (IPArea area = new IPArea()) { IPLocation ip = area.Search(loginArea); if (ip != null) { loginArea = ip.ToString(); } } this["LoginArea"] = loginArea; })) { NotFound(); } } else { Unauthorized(); } } }
public IPArea[] GetIPDBFromIO(string fileName) { IPArea[] result = null; if (!string.IsNullOrEmpty(fileName)) { IPDBFileName = fileName.Trim(); } if (string.IsNullOrEmpty(IPDBFileName)) { IPDBFileName = "ip.txt"; } try { string rootPath = GetExecRootPath(); string fullPath = string.Format("{0}{1}", rootPath, IPDBFileName); if (!File.Exists(fullPath)) { _LastError = string.Format("{0} 不存在", fullPath); return(result); } string lineInput = ""; string[] ipSeg = null; char[] splitors = new char[] { '\t', ';', ',' }; long ip1 = 0, ip2 = 0; string country = "", province = "", city = "", isp = ""; bool parseSucc = true; List <IPArea> buf = new List <IPArea>(); using (StreamReader sr = new StreamReader(fullPath, System.Text.Encoding.UTF8)) { lineInput = sr.ReadLine(); while (lineInput != null) { ipSeg = lineInput.Split(splitors); // 0 = ip1; 1= ip2; 2 = position; 3 = province; 4 = city; 5 = isp if (ipSeg != null && ipSeg.Length >= 3) { // 至少有前3项资料 if (!long.TryParse(ipSeg[0], out ip1)) { parseSucc = false; } if (!long.TryParse(ipSeg[1], out ip2)) { parseSucc = false; } country = ipSeg[2]; // 尝试读取更多资料 if (ipSeg.Length >= 4) { province = ipSeg[3]; } if (ipSeg.Length >= 5) { city = ipSeg[4]; } if (ipSeg.Length >= 6) { isp = ipSeg[5]; } if (parseSucc) { buf.Add(new IPArea(ip1, ip2, country, province, city, isp)); } } lineInput = sr.ReadLine(); } } if (buf.Count > 0) { result = new IPArea[buf.Count]; buf.CopyTo(result); } } catch (Exception ex) { _LastError = ex.Message; } finally { } return(result); }