WN

WN (https://www.wn.se/forum/index.php)
-   Serversidans teknologier (https://www.wn.se/forum/forumdisplay.php?f=4)
-   -   Blockera IP (https://www.wn.se/forum/showthread.php?t=23637)

pokerstjärna 2007-09-16 04:35

Hej.

Driver en mindre community sida och denna + två veckor tillbaka har den varit utsatt för många spammare.

Dom verkar ta sig förbi captchen också.

Finns det ingen kod man kan lägga till i scriptet på index filen så att dom inte kommer in alls?
Jag har då IP-adresserna listade.

Väldigt tacksam för hjälp. :unsure:

gsoc 2007-09-16 05:00

Kod:

<?
$bannad[0]="1.1.1.1";
$bannad[1]="2.1.1.1";
$bannad[2]="3.1.1.1";
$bannad[3]="4.1.1.1";
$bannad[4]="5.1.1.1";

if (in_array($_SERVER['REMOTE_ADDR'],$bannad))
{
header("HTTP/1.1 403 Forbidden");
exit;
}
?>

Borde fungera för vad du är ute efter?

Edit1: Kom ihåg att du kan faktiskt använda wildcards om du vill blockera tex ett c-nät, 1.1.1.*

Edit2: Om du vill kan du ju använda htaccess till det också:

Kod:

Order Allow,Deny
Deny From 1.1.1.1
Deny From 2.1.1.1
Deny From 3.1.1.1
Allow From All


pokerstjärna 2007-09-16 06:29

Citat:

Originally posted by gsoc@Sep 16 2007, 05:00
Kod:

<?
$bannad[0]="1.1.1.1";
$bannad[1]="2.1.1.1";
$bannad[2]="3.1.1.1";
$bannad[3]="4.1.1.1";
$bannad[4]="5.1.1.1";

if (in_array($_SERVER['REMOTE_ADDR'],$bannad))
{
header("HTTP/1.1 403 Forbidden");
exit;
}
?>

Borde fungera för vad du är ute efter?

Edit1: Kom ihåg att du kan faktiskt använda wildcards om du vill blockera tex ett c-nät, 1.1.1.*

Edit2: Om du vill kan du ju använda htaccess till det också:

Kod:

Order Allow,Deny
Deny From 1.1.1.1
Deny From 2.1.1.1
Deny From 3.1.1.1
Allow From All


Provade med att blockera min IP-adress och det fungerade utmärkt, Tack.

Om det finns andra sätt som är avancerade tekniskt sätt så får ni gärna posta :)

gsoc 2007-09-16 06:40

Citat:

Hello,

Well I for one am tired of fraudulent orders from the same old countries and I want to educate as many people as possible about stopping or at least lowering such orders on the internet. So here goes my first How-To :-)

Okay lets start.

Step 1 - Obtaining the country codes

Firstly, lets download the database of countries to IP address (which is provided courtesy of webhosting.info):

http://ip-to-country.webhosting.info/node/view/6

Download the zip file, extract it and then upload it to your server.

Step 2 - Setting up the database

Now create two MySQL tables using the following:

CREATE TABLE `country_list` (
`IP_FROM` double NOT NULL default '0',
`IP_TO` double NOT NULL default '0',
`country_code` char(2) NOT NULL default '',
`country_code2` char(3) NOT NULL default '',
`country_name` varchar(50) NOT NULL default ''
) TYPE=MyISAM;

CREATE TABLE country_blocks (
id int(5) NOT NULL auto_increment,
country_code char(2) NOT NULL default '',
KEY id (id)
) TYPE=MyISAM;

Okay now we want to load all the data into the country_list table. It's very quick if you can run this command from a MySQL prompt:

LOAD DATA INFILE '/directory/ip-to-country.csv' INTO
TABLE `country_list` FIELDS TERMINATED BY ',' ENCLOSED BY '"'
ESCAPED BY '\\' LINES TERMINATED BY '\r\n'

Lets also load some countries that have high fraud stats:

INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (1, 'AF');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (2, 'DZ');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (3, 'BD');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (4, 'BG');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (5, 'CN');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (6, 'HR');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (7, 'ID');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (8, 'JP');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (9, 'MY');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (10, 'NG');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (11, 'RO');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (12, 'SG');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (13, 'TW');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (14, 'VN');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (15, 'EG');

Blocks access from these countries:
AFGHANISTAN, ALGERIA, BANGLADESH, BULGARIA, CHINA, CROATIA, EGYPT, INDONESIA, JAPAN, MALAYSIA, NIGERIA, ROMANIA, SINGAPORE, TAIWAN, VIET NAM.

Step 3 - Doin the PHP

Great, that's that hard stuff! Now lets do the PHP stuff - its pretty easy!

Usually all sites created from php have a common.php or a file that is loaded before anything else if yours is like this then add the following function into that file:

function ip_access_check($ip)
{
$result = mysql_query("SELECT country_code FROM country_list WHERE IP_FROM <= inet_aton('" . $ip . "') AND IP_TO >= inet_aton('" . $ip . "')") or mysql_err();
$row = mysql_fetch_array($result);

$result = mysql_query("SELECT country_code FROM country_blocks WHERE country_code = '" . $row["country_code"] . "'") or mysql_err();

if ($row = mysql_fetch_array($result))
{
header("Location: /blocked.html");
exit;
}
}


If you don't have a common.php or similar then simply create a file called common.php with the function in it and include it in every page that you want using the include(); function.

Notice the "header("Location: /blocked.html");" in the above php function, well you can change this to point to a page that displays a message saying why you have blocked the page.

Now in your index.php and any other pages add the following just after calling the common.php file:

<?
ip_access_check($REMOTE_ADDR);
?>

Step 3 - Testing it

Test by adding your country into the country_blocks and then access that page which you have added the php code to.

Conclusion

I do hope this does lower any fraudulent orders you may get.. Good Luck with your endeavors and please let me know how it goes for you!

-Phil

Om du vill banna länder, gör en sökning på google så skall du ser att du finner svar, finns väldigt många olika metoder och verktyg för att banna folk, bästa vore väll om du använde dig av captcha så slipper du banna folk?

pokerstjärna 2007-09-16 06:54

Citat:

Originally posted by gsoc@Sep 16 2007, 06:40
Citat:

Hello,

Well I for one am tired of fraudulent orders from the same old countries and I want to educate as many people as possible about stopping or at least lowering such orders on the internet. So here goes my first How-To :-)

Okay lets start.

Step 1 - Obtaining the country codes

Firstly, lets download the database of countries to IP address (which is provided courtesy of webhosting.info):

http://ip-to-country.webhosting.info/node/view/6

Download the zip file, extract it and then upload it to your server.

Step 2 - Setting up the database

Now create two MySQL tables using the following:

CREATE TABLE `country_list` (
`IP_FROM` double NOT NULL default '0',
`IP_TO` double NOT NULL default '0',
`country_code` char(2) NOT NULL default '',
`country_code2` char(3) NOT NULL default '',
`country_name` varchar(50) NOT NULL default ''
) TYPE=MyISAM;

CREATE TABLE country_blocks (
id int(5) NOT NULL auto_increment,
country_code char(2) NOT NULL default '',
KEY id (id)
) TYPE=MyISAM;

Okay now we want to load all the data into the country_list table. It's very quick if you can run this command from a MySQL prompt:

LOAD DATA INFILE '/directory/ip-to-country.csv' INTO
TABLE `country_list` FIELDS TERMINATED BY ',' ENCLOSED BY '"'
ESCAPED BY '\\' LINES TERMINATED BY '\r\n'

Lets also load some countries that have high fraud stats:

INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (1, 'AF');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (2, 'DZ');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (3, 'BD');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (4, 'BG');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (5, 'CN');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (6, 'HR');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (7, 'ID');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (8, 'JP');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (9, 'MY');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (10, 'NG');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (11, 'RO');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (12, 'SG');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (13, 'TW');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (14, 'VN');
INSERT INTO `country_blocks` (`id`, `country_code`) VALUES (15, 'EG');

Blocks access from these countries:
AFGHANISTAN, ALGERIA, BANGLADESH, BULGARIA, CHINA, CROATIA, EGYPT, INDONESIA, JAPAN, MALAYSIA, NIGERIA, ROMANIA, SINGAPORE, TAIWAN, VIET NAM.

Step 3 - Doin the PHP

Great, that's that hard stuff! Now lets do the PHP stuff - its pretty easy!

Usually all sites created from php have a common.php or a file that is loaded before anything else if yours is like this then add the following function into that file:

function ip_access_check($ip)
{
$result = mysql_query("SELECT country_code FROM country_list WHERE IP_FROM <= inet_aton('" . $ip . "') AND IP_TO >= inet_aton('" . $ip . "')") or mysql_err();
$row = mysql_fetch_array($result);

$result = mysql_query("SELECT country_code FROM country_blocks WHERE country_code = '" . $row["country_code"] . "'") or mysql_err();

if ($row = mysql_fetch_array($result))
{
header("Location: /blocked.html");
exit;
}
}


If you don't have a common.php or similar then simply create a file called common.php with the function in it and include it in every page that you want using the include(); function.

Notice the "header("Location: /blocked.html");" in the above php function, well you can change this to point to a page that displays a message saying why you have blocked the page.

Now in your index.php and any other pages add the following just after calling the common.php file:

<?
ip_access_check($REMOTE_ADDR);
?>

Step 3 - Testing it

Test by adding your country into the country_blocks and then access that page which you have added the php code to.

Conclusion

I do hope this does lower any fraudulent orders you may get.. Good Luck with your endeavors and please let me know how it goes for you!

-Phil

Om du vill banna länder, gör en sökning på google så skall du ser att du finner svar, finns väldigt många olika metoder och verktyg för att banna folk, bästa vore väll om du använde dig av captcha så slipper du banna folk?

Det där är precis vad jag behövde, borde tänka på att googla mer :)
Grejen är att jag använder captcha men dom har tagit sig förbi det på något sätt :unsure: :blink: :(

men ska prova detta tack så mycket :)

melin 2007-09-16 09:27

Captcha är långt från perfekt tyvärr, det har funnits så länge så spammers har lärt sig hur dom ska göra

pokerstjärna 2007-09-17 03:02

gsoc: provade det du klistra in... well done! fungerar utmärkt.

crazzy 2007-09-17 07:37

ska slänga upp det på en sida som har en gästbok.. den fylls med ryska..

gsoc 2007-09-17 08:10

Ryska är väll chill, synd att jag varken pratar eller förstår :)

eliasson 2007-09-17 16:39

Citat:

Originally posted by melin@Sep 16 2007, 09:27
Captcha är långt från perfekt tyvärr, det har funnits så länge så spammers har lärt sig hur dom ska göra

Tycker det är märkligt att dom kan skapa sådana program som analyzerar CAPTCHA som även har mycket "garbarge" som ska störa den mekaniska faktorn, otroligt.


Alla tider är GMT +2. Klockan är nu 15:14.

Programvara från: vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Svensk översättning av: Anders Pettersson