Last post Jun 10, 2017 11:46 AM by mgebhard
Jun 09, 2017 01:27 PM|EgonMS1|LINK
In my ASP.Net 4 Internet application, the IP address information requires to be fetched of the devices (desktop/laptop/mobile).
Can you help confirm and provide some alternatives to capture this information?
1. Following is the code snippet to fetch the IPv4 information
string VisitorsIPAddr = string.Empty;
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
VisitorsIPAddr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
VisitorsIPAddr = HttpContext.Current.Request.UserHostAddress;
2. Can you confirm if using the server variable "REMOTE_ADDR" will resolve the issue for accessing the IP Address for all clients? What will be the limitations or use-cases which this might skip. Or how should I provision this.
3. How can I fetch the IPv6 Address for the visitors to the website? The Server ipconfig command displayed IPv4 & IPv6 address.
4. For the client, with both IPv4 & IPv6 address, which IP will be used for the request and therefore which IP should be used to save the information?
Also, it will be good to get some documentation link to resolve these.
Jun 09, 2017 08:36 PM|PatriceSc|LINK
You could also try
https://en.wikipedia.org/wiki/X-Forwarded-For#Alternatives_and_variations and it should be IPv4 or IPv6 depending on which protocol is used between this machine and your site. AFAIK REMOTE_ADDR should be the same than UserHostAddress. I would create a test
page but I believe that depending on how is handled by intermediate hardware what you'll get could be a private or public IP address. Ah also you could have a list rather than a single address, when going through multiple proxies.
Be prudent though with what you'll do with this information. In particular trying to use an IP as a reliable machine identifier likely won't work.
Jun 10, 2017 11:10 AM|hkbeer|LINK
Jun 10, 2017 11:46 AM|mgebhard|LINK
I agree. Anyway to get machine information?
Machine information is not part of the data send in the connection. The IP address will be the end point of the user's network which can be anything. As a matter of fact the IP can report as a node in your local network depending on how your network is
This is a networking/firewall question and should be directed to a networking support forum or your system admin.