Created
June 4, 2020 13:57
-
-
Save neokoenig/77f8dbc750cca35caa8d7062f7592150 to your computer and use it in GitHub Desktop.
Get IP Address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string function getIPAddress() { | |
local.rv = ""; | |
try { | |
try { | |
local.headers = getHttpRequestData().headers; | |
if (structKeyExists(local.headers, "X-Forwarded-For") && len(local.headers["X-Forwarded-For"]) > 0) { | |
local.rv = trim(listFirst(local.headers["X-Forwarded-For"])); | |
} | |
} catch (any e) {} | |
if (len(local.rv) == 0) { | |
if (structKeyExists(cgi, "remote_addr") && len(cgi.remote_addr) > 0) { | |
local.rv = cgi.remote_addr; | |
} else if (structKeyExists(cgi, "remote_host") && len(cgi.remote_host) > 0) { | |
local.rv = cgi.remote_host; | |
} | |
} | |
} catch (any e) {} | |
return local.rv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment