Find IP Address In ASP.NET Behind Proxy

Find IP Address Behind Proxy Or Client Machine In ASP.NET, If you want to find the IP address of visitors to your aspx page or application or wanna retrieve IP for other users than u need to write this code

Using this code we can find IP address of visitor even if visitor is behind any proxy

public string IpAddress()
{
string strIpAddress;
strIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (strIpAddress == null)
{
strIpAddress = Request.ServerVariables["REMOTE_ADDR"];
}
return strIpAddress;
}

To find IP address of a machine behind LAN you can use this code
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses
(strHostName).GetValue(1).ToString();


14 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Hi,

    How do i use the second option:

    "To find IP address of a machine behind LAN you can use this code"
    inmy code behind of an aspx page?

    Thanks.

    ReplyDelete
  4. Hi,

    How do I use the second option in my aspx page?

    Thanks

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. System.Net.Dns.GetHostAddresses
    (strHostName).GetValue(1).ToString();

    How do I use the above code in my aspx page?

    if i use the above code in my aspx means

    Index was outside the bounds of the array.
    Now what can i do? I need Dns Ip address

    ReplyDelete
  8. Hi, I use the Viusal C# Express edition. As far as I know the 2005 version that I am using is based on .Net 2.0, so it should have the System.Management namespace. However, I can't use that namespace... There is no intellisense or anything that popos up after I type it out... Do I need to have a server version of the OS to have System.Management

    Thanks in advance
    Shiva

    ReplyDelete
  9. i want to know the details about the ip address and client using browser and which location client open my website

    ReplyDelete
  10. Access Type (Browser),Location (IP address) [ ? ] Date/Time all these details in my website by using the c# and asp.net

    ReplyDelete
  11. tell me how to add more than 10 category

    ReplyDelete
  12. To solve the runtime error of Index was outside the bounds of the array use
    string ipaddress = System.Net.Dns.GetHostAddresses(hostname).GetValue(0).ToString();

    ReplyDelete
  13. This comment has been removed by a blog administrator.

    ReplyDelete
  14. how to find public ip address ??

    ReplyDelete