/// <summary> /// Given an ip string this method will return the correct image directly. This allows specifying /// this endpoint as the src attribute of an image for lists. /// </summary> /// <param name="ip">a string that is parsable into an ip address</param> /// <returns>a flag image as a gif.</returns> public ActionResult LocationFlag(string ip) { var fName = "us.gif"; var dbPath = Server.MapPath(ConfigurationManager.ConnectionStrings["geoip"].ConnectionString); if (System.IO.File.Exists(dbPath)) { var ls = new MaxMind.GeoIP.LookupService(dbPath, MaxMind.GeoIP.LookupService.GEOIP_STANDARD); MaxMind.GeoIP.Location loc; if (!ip.StartsWith("10.")) loc = ls.getLocation(System.Net.IPAddress.Parse(ip)); else loc = new MaxMind.GeoIP.Location() { countryName = "US", countryCode = "US", city = "LAN", regionName = "Internal Address" }; if (loc != null) fName = String.Format("{0}.gif", loc.countryCode); } return new FilePathResult(Server.MapPath(String.Format("~/Contents/countryflags/{0}", fName)), "image/gif"); }
private MaxMind.GeoIP.LookupService GetLookupService() { return(_cache.Get("GeoCountryLookup", () => { var lookupService = new MaxMind.GeoIP.LookupService(_webHelper.MapPath("~/App_Data/GeoIP.dat")); return lookupService; })); }
/// <summary> /// Returns GEOIP data for a given IP address. /// </summary> /// <remarks>While technically this is not data in the analysys portion of the database it is related</remarks> /// <param name="ip">a string that is parsable into an ip address</param> /// <returns>any location information that can be found for the ip address or null if no entry was found.</returns> public ActionResult Location(string ip) { var result = new JavaScriptResult(); var dbPath = Server.MapPath(ConfigurationManager.ConnectionStrings["geoip"].ConnectionString); if (System.IO.File.Exists(dbPath)) { var ls = new MaxMind.GeoIP.LookupService(dbPath, MaxMind.GeoIP.LookupService.GEOIP_STANDARD); MaxMind.GeoIP.Location loc; if (!ip.StartsWith("10.")) loc = ls.getLocation(System.Net.IPAddress.Parse(ip)); else loc = new MaxMind.GeoIP.Location() { countryName = "US", countryCode = "US", city = "LAN", regionName = "Internal Address" }; if (loc != null) result.Script = "{" + string.Format("areaCode:{0}, city:'{1}', countryCode:'{2}', countryName:'{3}', latitude:{4}, longitude:{5}, metroCode:{6}, postalCode:'{7}', region:'{8}', regionName:'{9}'", loc.area_code, loc.city, loc.countryCode, loc.countryName, loc.latitude, loc.longitude, loc.metro_code, loc.postalCode, loc.region, loc.regionName) + "}"; else result.Script = "{}"; } else result.Script = "{}"; return result; }
/// <summary> /// Renders a page that displays information about a specific client ip address /// </summary> /// <returns></returns> public ActionResult Client(string ip) { if (string.IsNullOrWhiteSpace(ip)) return new HttpNotFoundResult(); MongoServer server = MongoServer.Create(ConfigurationManager.ConnectionStrings["mongodb"].ConnectionString); var db = server.GetDatabase("events"); var iisEvents = db.GetCollection("iis"); var results = iisEvents.Distinct("UserAgent", new QueryDocument(QueryDocument.Parse("{ClientAddress:'" + ip+ "'}"))); ViewBag.UserAgents = results.Select(b => GetBrowserCap(b.ToString().Replace('+',' '))).ToArray(); var dbPath = Server.MapPath(ConfigurationManager.ConnectionStrings["geoip"].ConnectionString); if (System.IO.File.Exists(dbPath)) { var ls = new MaxMind.GeoIP.LookupService(dbPath, MaxMind.GeoIP.LookupService.GEOIP_STANDARD); if (!ip.StartsWith("10.")) ViewBag.Location = ls.getLocation(System.Net.IPAddress.Parse(ip)); else ViewBag.Location = new MaxMind.GeoIP.Location() { countryName="US", countryCode="US", city="LAN", regionName="Internal Address" }; } ViewBag.ClientAddress = ip; return View(); }