protected override ValidationResult IsValid(object value, ValidationContext validationContext) { IPGeolocationResult ipGeo = (IPGeolocationResult)validationContext.ObjectInstance; IPAddress ipAddr; if (IPAddress.TryParse(ipGeo.ip, out ipAddr)) { return(ValidationResult.Success); } return(new ValidationResult("Invalid IP Address")); }
public override void getData(IPGeolocationResult result) { IPAddress ipAddr = IPAddress.Parse(result.ip); _logger.LogInformation("ASN check for ip = " + result.ip); var data = dbReader.Find <Dictionary <string, object> >(ipAddr); if (data != null) { if (data.ContainsKey("autonomous_system_organization")) { result.asn = data["autonomous_system_organization"].ToString(); } } }
public override void getData(IPGeolocationResult result) { IPAddress ipAddr = IPAddress.Parse(result.ip); _logger.LogInformation("Geolocation for ip = " + result.ip); Dictionary <string, object> data = dbReader.Find <Dictionary <string, object> >(ipAddr); if (data != null) { if (data.ContainsKey("city")) { Dictionary <string, object> city = (Dictionary <string, object>)data["city"]; Dictionary <string, object> names = (Dictionary <string, object>)city["names"]; if (names.ContainsKey("en")) { result.city = names["en"].ToString(); } } if (data.ContainsKey("subdivisions")) { List <object> specifics = (List <object>)data["subdivisions"]; Dictionary <string, object> names = (Dictionary <string, object>)specifics[0]; names = (Dictionary <string, object>)names["names"]; if (names.ContainsKey("en")) { result.state = names["en"].ToString(); } } if (data.ContainsKey("country")) { Dictionary <string, object> country = (Dictionary <String, object>)data["country"]; if (country.ContainsKey("iso_code")) { result.country = country["iso_code"].ToString(); } } } }
public abstract void getData(IPGeolocationResult result);