Find IP Address in ASP.NET Behind Proxy

Find IP Address in ASP.NET Behind Proxy

If you want to find the IP address of visitors to your aspx page or application or wanna retrieve IP for other uses 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

12 comments:

muthu said...

Hai,
Thanks for Your tips.But we can easily find the ip address using this linkwww.ip-details.com


Anonymous said...

For more details you may check
http://www.webtoolhub.com/tn561354-what-is-my-ip.aspx


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

Can anyone recommend the well-priced Script Deployment software for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central malware detection
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!


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


srinivas said...

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


srinivas said...

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


M. Abdus Salam said...

tell me how to add more than 10 category


Fulwaria interiors said...

nice tutorial...