mike55 Posted August 3, 2006 Posted August 3, 2006 Hi all I am trying to obtain the user IP address, to determine what country that they are comming from. The purpose of this information is to redirect the user to a particular page that is configured for the individual country. Any suggestions on how to achieve this? So far I have managed to obtain the IP address of the server, but not the other way around. Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted August 3, 2006 Administrators Posted August 3, 2006 Hi all I am trying to obtain the user IP address, to determine what country that they are comming from. The purpose of this information is to redirect the user to a particular page that is configured for the individual country. Any suggestions on how to achieve this? So far I have managed to obtain the IP address of the server, but not the other way around. Mike55. Request.UserHostAddress should do the trick. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mike55 Posted August 3, 2006 Author Posted August 3, 2006 Many Thanks for the reply. Here is the code that I have started using: Private Sub DetermineUsersIPAddress() 'Response.Write(Request.ServerVariables("REMOTE_ADDR")) Dim strIp As String strIp = Request.ServerVariables("HTTP_X_FORWARDED_FOR") If strIp = "" Then strIp = Request.ServerVariables("REMOTE_ADDR") End If Response.Write(strIp) End Sub Now the next step is to find the country that the IP address belongs to. Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted August 3, 2006 Administrators Posted August 3, 2006 '.Net 2.0 Dim host As String host = System.Net.Dns.GetHostEntry(Request.UserHostAddress).HostName '.Net 1 Dim host As String host = System.Net.Dns.GetHostByAddress(Request.UserHostAddress) The variable host should contain the fully qualified domain name - the country might be obtainable from parsing this out. Be aware this is not 100% (probably nowhere near in fact.) You might find a better solution is to run a WHOIS query agains the IP address - http://www.vbdotnetheaven.com/UploadFile/jghosh/WhoIsQuery04182005050349AM/WhoIsQuery.aspx?ArticleID=63b59267-40fc-40d4-b724-df0d77dbef97 has a sample that might help. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.