Trying to build some customisation into your website? Or simply block some malicious IPs from accessing your content?
We will cover 2 methods:
This method uses diafygi "STUN IP Address requests for WebRTC".
This code snippet is based on newly-released WebRTC support in Chrome and Firefox that allows request for STUN servers to be made, resulting in the ability to access local and public IP addresses for your visitors.
The good news is that these calls can't be blocked by ad blocking plugins and widgets because they are made outside of the XMLHttpRequest instance. Given that 20 to 30% of the internet users are browsing with Adblockers, this is perfect if you want to ensure aconsistent experience for all your users.
Copy and paste the following code into your web page:
Now you can use the following function to get the IP as soon as it's found:
Abstract provides a free IP Geolocation API that has a method to retrieve the IP of a visitor.
You can use learn more and get your free API key here: https://www.abstractapi.com/ip-geolocation-api