public string GetCountry(string ip) { string[] arrIP = ip.Split('.'); double ip0 = Convert.ToDouble(arrIP[0]); double ip1 = Convert.ToDouble(arrIP[1]); double ip2 = Convert.ToDouble(arrIP[2]); double ip3 = Convert.ToInt32(arrIP[3]); double factor0 = 16777216; double factor1 = 65536; double factor2 = 256; double iIPNum = (ip0 * factor0) + (ip1 * factor1) + (ip2 * factor2) + ip3; //iIPNum = arrIP(0) * 16777216 + arrIP(1) * 65536 + arrIP(2) * 256 + arrIP(3) var ipCountry = _db.IpCountries.FirstOrDefault(x => x.StartNum <iIPNum && x.EndNum> iIPNum); if (ipCountry != null && !string.IsNullOrWhiteSpace(ipCountry.CountryId)) { return(ipCountry.CountryId); } var xverify = new XVerifyRepository(); return(xverify.GetCountryFromIp(ip)); }
public XVerifyManager() { _db = new GloshareContext(); _xverifyRepository = new XVerifyRepository(); }
public XVerifyController() { _xverifyRepository = new XVerifyRepository(); }