Manoj Bisht

Manoj Bisht

  • NA
  • 135
  • 0

Get Visitor's IP Address

Mar 31 2009 8:30 AM
Hello Friend,

I want to get the Visitor's IP Address. For it, i'm using the following code

string hostName = Dns.GetHostName();

IPHostEntry hostEntry = Dns.GetHostEntry(hostName);
IPAddress[] ipAddress = hostEntry.AddressList;

string name = null;
for(int i=0;i<ipAddress.Length;i++)
{
name = name + ipAddress[i].ToString()+"<br>";
}

Response.Write(name.ToString());


This code is showing the correct IPAddress of the local computer on localhost but as i upload this code over my server it gives me the following IPAddress not of my computer


66.63.181.68
66.63.181.93
216.45.55.186


Secondly, i use the following code

string hostName1 = Request.UserHostName.ToString();
Response.Write(hostName1.ToString());


But this is giving the IPAddress of the Main computer, I mean there are four computers, sharing the internet connection from my PC and when i visit the page from any of those computers it always give me the IP of my PC

Answers (2)