Bloquear un rango de IP’s

Existen muchas formas de bloquear direcciones IP específicas. Desde beanBlog nos llega unas sugerencias en 4 lenguajes: PHP, ASP, ASP .NET y JavaScript. (Otra sugerencia para PHP lo puedes encontrar en este artículo)

PHP

    $blockedIP = array();
$blockedIP[] = “x.x.x.x”;
$blockedIP[] = “x.x.x.x”;
$blockedIP[] = “x.x.x.x”;
$blockedIP[] = “x.x.x.x”;

$incomingIP = $_SERVER["REMOTE_ADDR"];

for($i=0; $i<count($blockedIP); $i++){

if($blockedIP[$i] == $incomingIP){

echo “<script>alert(’you are not allowed to visit this site anymore’);</script>”;
header(“location: http://www.google.com”);
break;

}

}

ASP

    Dim blockedIP(2)  ‘fixed size array
blockedIP(0) = “x.x.x.x”
blockedIP(1) = “x.x.x.x”
blockedIP(2) = “x.x.x.x”

Dim incomingIP
incomingIP = Request.ServerVariables(“REMOTE_ADDR”)

For i=0 to UBound(blockedIP)

if(blockedIP(i) = incomingIP) then

response.write(“<script>alert(’you are not allowed to visit this site anymore’);</script>”)
response.redirect(“http://www.google.com”)
exit for

end if

Next

ASP .NET

    ArrayList blockedIP = new ArrayList();
blockedIP.Add(“x.x.x.x”);
blockedIP.Add(“x.x.x.x”);
blockedIP.Add(“x.x.x.x”);

string incomingIP = Request.UserHostAddress;

foreach (string x in blockedIP){

if (x == incomingIP){

response.write(“<script>alert(’you are not allowed to visit this site anymore’);</script>”);
response.redirect(“http://www.google.com”);
break;

}

}

JavaScript. 

El uso de JavaScript para bloquear IP\’s es innecesario, ya que esto se puede hacer desde el lado del servidor facilmente. Pensemos también en que el usuario puede desactivar JavaScript en el navegador. De todas formas para efectos educativos…

<script language=”javascript” type=”text/javascript”>

var blockedIP = new Array();

blockedIP[0] = “x.x.x.x”;
blockedIP[1] = “x.x.x.x”;
blockedIP[2] = “x.x.x.x”;

//PHP –> <?php echo $_SERVER["REMOTE_ADDR"]; ?>
//ASP –> <%= Request.ServerVariables(”REMOTE_ADDR”) %>
//ASP.NET –> <%= Request.UserHostAddress %>
var ip = ‘<?php echo $_SERVER["REMOTE_ADDR"]; ?>‘;

for(var i=0; i<blockedIP.length; i++){

if(blockedIP[i] == ip){

alert(“you are not allowed to visit this site anymore”);
window.location = “http://www.google.com”;
break;

}

}

</script>

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Wanderz Blog by Crimson Themes.