I'm open to using SSJS or AMPscript to find the IP address of the client who is accessing a landing page. I tried this AMPscript:
Which resulted in a blank page.
Hmmm, that should work but it looks like it's not for some reason. I've tried a few different HTTP header fields and the
HTTPRequestHeader() AMPscript function is not returning any of them.
Never mind. As an alternative approach, I'd suggest using an external service to retrieve the client IP address. There are plenty of them out there but ipify.org looks suitable as it's super lightweight, it doesn't have any rate limiting and supports both IPv4 and IPv6 addresses.
<p>Your IP address is: %%=HTTPGet('https://api.ipify.org')=%%</p>
Your IP address is: 22.214.171.124
126.96.36.199 belongs to Salesforce, so this won't work with landing pages either. See below for solution.
While this should work (it doesn't) on a landing page, it doesn't appear to work on a CloudPage as it appears that the CloudPage CDN is making a reverse proxy request and displays an IP address used by the data center hosting the CloudPage, and not the client IP.
If you are using landing pages (available on earlier accounts) then you should be fine, but CloudPages won't work and I can't come up with a solution for this. I've tried using SSJS, and:
Will return the Host value in the HTTP header, but the following HTTP headers return the same empty value as its
HTTPRequestHeader() AMPscript counterpart:
As we seem to have exhausted our server-side options for CloudPages, the simplest/only solution would be to:
For purposes of my example, I'm just printing the IP address on the page, but you can use it to update a Data Extension, etc. I'm assuming that you are not adding any other cookies on your page. If you are, then you will need to update the
Replace() function accordingly.
I ran across the same problem today. In the end I found that, in SSJS, you can use
which returns the client IP address as a string. Worked for me on a Landing Page.