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();


If you like this post than join us or share

14 comments:

nivetha said...

This comment has been removed by a blog administrator.


Anonymous said...

This comment has been removed by a blog administrator.


Emmao said...

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.


Emmao said...

Hi,

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

Thanks


Anonymous said...

This comment has been removed by a blog administrator.


Anonymous said...

This comment has been removed by a blog administrator.


Anonymous said...

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


Anonymous said...

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


Unknown said...

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


Unknown said...

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


a said...

tell me how to add more than 10 category


Anonymous said...

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();


Anonymous said...

This comment has been removed by a blog administrator.


Anonymous said...

how to find public ip address ??


Find More Articles