Public IP Macro Question

Yoyo Bubble asked on May 18, 2018 22:10

Hello Fellow Kenticans!

Greetings and salutations. Is there a way to grab a users public IP address via macro?

I'm currently using this macro: CustomMacros.CaptureIP()

But its apparently only grabbing either the server IP or the IPV4 address.

Any thoughts?

Thanks!

Correct Answer

Sir McShneebles answered on June 13, 2018 19:59

Hello Yoyo,

I do believe I hath come up with a fix for this query.

Take a gander at this page: https://ourcodeworld.com/articles/read/257/how-to-get-the-client-ip-address-with-javascript-only

Here ye, here ye you can see a solution for grabbing both the public IP address as well as the private in both HTTP and HTTPS environmentos.

Then simply create a cookie that storeth this information in the cookie chamber. something similar to:

<script>
// usage for public ip
function getIP(json) {
    // add an IP cookie with an expiration date
    function setIpCookie(cname, cvalue, cexpires) {
        var date = new Date();
        date.setTime(date.getTime() + (7*24*60*60*1000));
        cname = "ipAddress";
        cvalue = json.ip;
        cexpires = date.toUTCString();
        document.cookie = cname + "=" + cvalue + "; expires=" + cexpires + "; path=/";
    }
    setIpCookie();
}
</script>

Then you you can surely use the Kentico macro for retrieving thine value:

'ipAddress' : '{%Cookies["ipAddress"]|(identity)GlobalAdministrator%}',

Regards,

Sir McShneebles

0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on May 18, 2018 23:23 (last edited on May 18, 2018 23:23)

{%Ip%}

1 votesVote for this answer Mark as a Correct answer

Yoyo Bubble answered on May 24, 2018 15:38

Hey Peter

Thanks for the response! Unfortunatley, this macro still displays the IPv4 address as the previous macro did and not my public IP (what I'd expect to see if I google "what's my IP")

is this possible?

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on May 29, 2018 02:21

It depends from where you are accessing your site. If you access your site from some public computer it will show your public IP (like google). If you are accessing from internal network (inside the office) - it is still your internal network address

0 votesVote for this answer Mark as a Correct answer

Jeecy Beland answered on June 8, 2018 18:11

Hi Peter, we got the issue here, at TEC centers. We are finally with Kentico 10, and we are checking the IP of the customers for the GDPR regulation, we use the native macro {%Ip%} and still investigate why, but the Ip always change, sometimes we are in Russia, Danemark, France etc.. In reality we are in Longueuil. Do you have any clue?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.