Unable to get user IP address (proxy / firewall / load balancer)

I used the code below to get the client ip with asp.net earlier, but after I switched to VDS, this function will only start returning my subnet mask, which is 178.18.198.1 or 178.18.198.2. Can someone help me with this problem?

Private Function GetIPAddress() As String Dim sIPAddress As String = Nothing sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR") If String.IsNullOrEmpty(sIPAddress) Then sIPAddress = Request.ServerVariables("REMOTE_ADDR") End If Return sIPAddress End Function 

EDIT

Found a similar problem here :

Many 32-bit versions of 2008 were deployed by standard web servers using citrix netscaler isapi (netscaler is a load balancer), in all cases the client's IP address is logged in standard IIS logs. In a new project, I was asked to deploy 2008 R2, configured IIS 7.5 in the same way as I configured IIS 7.0 in the past, this time, however, the client ip returns the load balancing address to the logs. Here is the weird part, I installed the "extended log", and this is mapping the client IP address correctly, so isapi does the job. Googled this one to death and could use some tips.

I also found the ISAPI filter module, but can't get it working: devcentral.f5.com/x_forwarded_for_log_filter_for_windows_servers

+6
source share
2 answers

The problem is resolved using HTTP_CLIENT_IP instead of REMOTE_ADDR in source code files.

The issue with IIS logs was resolved by installing the IIS Advanced Logging module suggested here . I also received the error "503: Service Unavailable" after installing Advanced Logging, but I solved it by granting read and write permissions for each Program Files \ IIS folder and running application pools.

http://kb.parallels.com/6735

Another suggested solution here :

In NetScaler, under "load balancing", "services", then under the advanced tab, in the settings, check the "Use source IP address" and "Client IP address" field, then in the "CLIENT-IP" header field

+4
source

I use

 IP.Text = Request.UserHostAddress; 

In C #. Does this work for you?

0
source

Source: https://habr.com/ru/post/888193/


All Articles