问题
From an ASP.NET page I'm able to retrieve the client's IP address (at least the apparent one).
I would like to know if there is a free service that I can access from code-behind, that will return the country (no need for city) when queried with the IP.
I can't make do with web http based services where you have to enter the IP manually, I have thousands of visits per day!
Any clue welcome.
回答1:
Yes, Check It Out!
Good luck!
EDITED: Since you did not specify a language I went ahead and created my own key for testing purposes and made this little sample. This gets the Country of any given IP address. Good luck.
Try
Dim webClient As WebClient = New WebClient
'I am at work so i need a proxy authentication
'webClient.Proxy.Credentials = New NetworkCredential("username", "password")
Dim stream As Stream = webClient.OpenRead("http://api.ipinfodb.com/v3/ip-country/?key=<key here>&ip=" & Context.Request.ServerVariables("REMOTE_ADDR"))
Dim sReader As New StreamReader(stream)
Dim content As String = sReader.ReadToEnd()
Response.Write(content.Split(";")(4))
Catch ex As Exception
Response.Write("Error occured")
End Try
回答2:
I use WIPmania, very, very easy:
http://api.wipmania.com/123.45.67.89
returns two-letter country code ("KR" Republic of Korea)
KR
回答3:
Found this that might be up your alley.
IP2Location
来源:https://stackoverflow.com/questions/8657855/geoip-find-country-from-asp-net