In C# there is a library of computer code in use that determines the Province - City - Country through the WAN IP address? I've seen some code on the net but it doesn't work
Loading
In C# there is a library of computer code in use that determines the Province - City - Country through the WAN IP address? I've seen some code on the net but it doesn't work
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 1, 2023, 3:36 AM EST
Hello Dong,
You can use below lib in C#.
These libraries can be easily integrated into a C# application and used to retrieve the location information for a given IP address.
Thanks
Naimish
Vishal JoshiRank #377 · 6.7K reputationPosted Feb 1, 2023, 5:10 AM EST
Hello
Please review the below article c# Corner to get expected result.
https://www.c-sharpcorner.com/UploadFile/rahul4_saxena/geographical-information-by-ip-address-in-Asp-Net-and-C-Sharp/
Thanks
Dong Lam TrienRank #1,538 · 1K reputationPosted Feb 2, 2023, 3:02 AM EST
do you have an example code that runs on winform ?
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 2, 2023, 3:23 AM EST
Hello Dong,
First, you need to get an API key from a reliable IP Geolocation service, such as IPGeolocationAPI.
Then you can use below method to get the data.
private void btnGetLocation_Click() { string apiKey = "XXX"; string ipAddress = "XXX"; string url = $"https://api.ipgeolocation.io/ipgeo?apiKey={apiKey}&ip={ipAddress}"; using (WebClient client = new WebClient()) { string json = client.DownloadString(url); JObject obj = JObject.Parse(json); var txtCity = obj["city"].ToString(); var txtCountry = obj["country_name"].ToString(); var txtContinent = obj["continent_name"].ToString(); var txtTimezone = obj["time_zone"].ToString(); var txtLatitude = obj["latitude"].ToString(); var txtLongitude = obj["longitude"].ToString(); } }Thanks
Naimish Makwana
Dong Lam TrienRank #1,538 · 1K reputationPosted Feb 2, 2023, 10:34 PM EST
I don't quite understand this problem, do you have an example ?
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 2, 2023, 10:39 PM EST
Hi Dong,
Example is already given below.
Thanks
Naimish