IP Address Blocker (Client-Side)
Redirect unwanted visitors. This script fetches the user's IP address from a public API and checks it against a list of blocked IPs. If a match is found, the user is redirected away.
Your IP Address:
Loading...
Note: This uses the 'ipify' public API.
Copy the Script
<script>
// List of blocked IPs
var blockedIPs = ["123.45.67.89", "98.76.54.32"];
// Fetch IP from API
fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(data => {
var userIP = data.ip;
if (blockedIPs.includes(userIP)) {
alert("Access Denied for IP: " + userIP);
window.location.href = "https://www.google.com";
}
})
.catch(error => console.error('Error fetching IP:', error));
</script>
Frequently Asked Questions
No. JavaScript runs in the browser and does not have native access to the IP address. It must ask an external server (API) like 'ipify' or 'ip-api' to retrieve it.
No. A user can easily block the API request or disable JavaScript to bypass this. Real IP blocking must be done on your server (using .htaccess or Firewall rules).
It is useful for simple redirects, non-critical content gating, or showing different messages to internal company employees based on their office IP.