Web Connection
REQUEST.GetIpAdress()
Hello,
Just want to share part my work on spam detection and IP blocking in firewall I found this in a log using REQUEST.GetIpAdress()

By default Web connection return HTTP_X_FORWARDED_FOR who's used by some spammers hoping the site trusts them
The way I do it
* Reverse proxy detection - check if request comes from reverse proxy server
FUNCTION detectreverseproxy(toRequest)
LOCAL lcRemoteIP
lcRemoteIP = toRequest.ServerVariables("REMOTE_ADDR")
IF lcRemoteIP == THIS.cWanServerLocalIp
THIS.lHttpIsForwarded = .T.
ELSE
THIS.lHttpIsForwarded = .F.
ENDIF
ENDFUNC
FUNCTION GetClientIp(toRequest) AS String
LOCAL lcIp, lcForwarded, lnCount
lcIp = ALLTRIM(toRequest.ServerVariables("REMOTE_ADDR"))
IF SERVER.oUrl.lHttpIsForwarded
lcForwarded = ALLTRIM(toRequest.ServerVariables("HTTP_X_FORWARDED_FOR"))
* X-Forwarded-For is a list, and only its last entry can be trusted.
lnCount = GETWORDCOUNT(lcForwarded, ",")
IF lnCount > 0
lcIp = ALLTRIM(GETWORDNUM(lcForwarded, lnCount, ","))
ENDIF
ENDIF
* Remove the port: 1.2.3.4:5678
IF OCCURS(":", lcIp) = 1
lcIp = LEFT(lcIp, AT(":", lcIp) - 1)
ENDIF
RETURN lcIp
ENDFUNC