Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neokoenig/77f8dbc750cca35caa8d7062f7592150 to your computer and use it in GitHub Desktop.
Save neokoenig/77f8dbc750cca35caa8d7062f7592150 to your computer and use it in GitHub Desktop.
Get IP Address
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