public class GetGeoLocation
public IPData GetIPGeoLocation(string IP)
WebClient client = new WebClient();
string response = client.DownloadString("http://ip-api.com/json/" + IP);
IPData ipdata = JsonConvert.DeserializeObject<IPData>(response);
if (ipdata.status == "fail")
throw new Exception("Invalid IP");
public static void Main()
IPData ipdata = new GetGeoLocation().GetIPGeoLocation("208.80.152.201");
Console.WriteLine(ipdata.status + " - Your IP belongs to '" + ipdata.region + " - " + ipdata.country + "'");
public string status { get; set; }
public string country { get; set; }
public string countryCode { get; set; }
public string region { get; set; }
public string regionName { get; set; }
public string city { get; set; }
public string zip { get; set; }
public string lat { get; set; }
public string lon { get; set; }
public string timezone { get; set; }
public string isp { get; set; }
public string org { get; set; }
public string @as { get; set; }
public string query { get; set; }