Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

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
Posted
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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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.

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
Posted

'.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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...