Den 11-04-2012 15:09, Erik Ginnerskov skrev:
> Christian Kragh wrote:
>
>> Hvorfor så mange krumspring...
>>
>> Brug en som denne:
>>
>> <Files *>
>> order deny,allow
>> deny from
41.0.0.0/8
>> deny from .....
>> deny from
216.252.245.0/24
>> </Files>
>> <Files .htaccess>
>> deny from all
>> </Files>
>>
>> i din .htaccess så er du ude over problemet med de kendte steder...
>
> Det rammer kun enkelte IP-adresser og skal ustandselig opdateres, hver
> gang banditterne skifter IP.
>
Det gør den da ikke når man bruger /8, /24 og så videre...
Jeg har dog set at jeg har en smartere løsning, der også rammer enkelt
ipadresser...
Jeg har lavet et script hvor jeg har mine landekoder i en tabel ligesom
den Karl Erik har lavet, men jeg syntes performance er lidt for langsom,
så her er den i både asp og php, desuden omskrevet således at de der er
tilladt kommer ind, resten gør ikke, så rammer man alle lande som ikke
er whitelistet:
Jeg har lagt SQLdataen her:
www.5mm.dk/block.zip
<?php
$con = mysql_connect("localhost","DBUser","dbPassword");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("DBTable", $con);
$result = mysql_query("SELECT tblip.country1, tblip.country3 FROM tblip
WHERE StartIP <= " . iptocountry($_SERVER['REMOTE_ADDR']) . " AND EndIP
>= " . iptocountry($_SERVER['REMOTE_ADDR']) . ";",$con);
if (mysql_num_rows($result)){
while ($row = mysql_fetch_array($result)) {
if (($row['country1'] == "AU") || ($row['country1'] == "AT") ||
($row['country1'] == "BE") || ($row['country1'] == "CA") ||
($row['country1'] == "DK") || ($row['country1'] == "EU") ||
($row['country1'] == "FO") || ($row['country1'] == "FI") ||
($row['country1'] == "FR") || ($row['country1'] == "GF") ||
($row['country1'] == "PF") || ($row['country1'] == "DE") ||
($row['country1'] == "GR") || ($row['country1'] == "GL") ||
($row['country1'] == "IS") || ($row['country1'] == "IE") ||
($row['country1'] == "IT") || ($row['country1'] == "LI") ||
($row['country1'] == "LU") || ($row['country1'] == "MC") ||
($row['country1'] == "NL") || ($row['country1'] == "NO") ||
($row['country1'] == "PT") || ($row['country1'] == "ES") ||
($row['country1'] == "SE") || ($row['country1'] == "CH") ||
($row['country1'] == "GB") || ($row['country1'] == "US")) {
} else {
blocked();
}
}
} else {
blocked();
}
mysql_close($con);
function blocked() {
header("Location:
https://www.google.com");
die();
return $_retval;
}
function iptocountry($ip) {
$numbers = preg_split( "/\./", $ip);
include("ip_files/".$numbers[0].".php");
$code = ($numbers[0] * 16777216) + ($numbers[1] * 65536) +
($numbers[2] * 256) + ($numbers[3]);
return $code;
}
?>
Og så i ASP
<%
Set Conn = Server.CreateObject("ADODB.Connection")
DSN = "DRIVER={MySQL ODBC 3.51
Driver};Server=Server;Port=3306;Database=DBName;User=DBUser;Password=DBPassword;Option=3;"
Conn.Open DSN
strSQL = "SELECT tblip.country1, tblip.country3 FROM tblip WHERE StartIP
<= " & IPToNum(Request.ServerVariables("Remote_Addr")) & " AND EndIP >=
" & IPToNum(Request.ServerVariables("Remote_Addr")) & ";"
Set rs = Conn.Execute(strSQL)
if rs.eof then
rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
blocked()
end if
if not
instr(",AU,AT,BE,CA,DK,EU,FO,FI,FR,GF,PF,DE,GR,GL,IS,IE,IT,LI,LU,MC,NL,NO,PT,ES,SE,CH,GB,US,",rs("country1"))
> 0 then
rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
blocked()
end if
rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
function blocked()
response.redirect "
https://www.google.com"
end function
Function IPToNum(strIP)
Dim numOctetsArray
Dim i
numOctetsArray = Split(strIP,".")
If UBound(numOctetsArray) <> 3 Then
IPToNum = -1
Exit Function
End If
For i = 0 to 3
If Not IsNumeric(numOctetsArray(i)) Then
IPToNum = -2
Exit Function
End If
If numOctetsArray(i) > 254 Then
IPToNum = -3
Exit Function
End If
Next
IPToNum = numOctetsArray(0) * (2^24)
IPToNum = IPToNum + numOctetsArray(1) * (2^16)
IPToNum = IPToNum + numOctetsArray(2) * (2^8)
IPToNum = IPToNum + numOctetsArray(3)
End Function
%>
--
Venlig hilsen
Christian Kragh
------------------
www.Plantimer.dk
www.HTML-Faq.dk