private void ViewIpAddress(IpAddressData ipAddressData) { this.textBoxIpAddressPart1.Text = ipAddressData.Part1.ToString(); this.textBoxIpAddressPart2.Text = ipAddressData.Part2.ToString(); this.textBoxIpAddressPart3.Text = ipAddressData.Part3.ToString(); this.textBoxIpAddressPart4.Text = ipAddressData.Part4.ToString(); }
private RootIpAddressLookup GetData(List <string> ips) { var searchFields = new List <string> { "query", "status", "country", "regionName", "city", "district", "zip", "isp", "org", "as", "lat", "lon", "blacklist" }; var client = new RestClient("http://ip-api.com"); List <BulkIpBody> body = new List <BulkIpBody>(); var fieldsToUse = ""; foreach (string f in searchFields) { fieldsToUse += string.Format("{0},", f); } fieldsToUse = fieldsToUse.TrimEnd(','); foreach (string s in ips) { if (!string.IsNullOrEmpty(s) && s != "127.0.0.1") { BulkIpBody bodyItem = new BulkIpBody { query = s, fields = fieldsToUse }; body.Add(bodyItem); } } string output = JsonConvert.SerializeObject(body); var request = new RestRequest("/batch/}", Method.POST); request.AddParameter("application/json", output, ParameterType.RequestBody); // execute the request //client.Timeout = 5000000; IRestResponse response = client.Execute(request); var content = response.Content; // raw content as string JsonSerializerSettings settings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }; var data = new List <IpAddressData>(); var results = JsonConvert.DeserializeObject <List <IpApiResponse> >(content, settings); foreach (var r in results) { var d = new IpAddressData() { ASN = r.As, City = r.city, Country = r.country, District = r.district, IpAddress = r.query, ISP = r.isp, Latitude = r.lat, Longitude = r.lon, Organization = r.org, RegionName = r.regionName, Status = r.status, Zipcode = r.zip }; data.Add(d); } return(new RootIpAddressLookup() { IpAddressData = data }); }