View Full Version : htaccess help
Chella
09-28-2007, 11:58 AM
I'm trying to block a visitor through htaccess, the problem is they're using DSL and the IP isn't static. So far I've been blocking it by range, but that changes a lot too.
Is there any way I can block the visitor by the PPPox Pool (for example: rback6.crchtx) ?
SiriusB
09-28-2007, 12:40 PM
If they are on a dynamic IP there isn't a lot you can do - and anything you do may block someone other than the guy you apparantly don't like.
Chella
09-28-2007, 03:35 PM
Well, nuts. Thanks anyway. I'll just deal with it :)
sjlplat
09-28-2007, 04:53 PM
This can be done with PHP. Get a reverse DNS on the IP address, then put it into an array. Insert an exit() into the HTML if the domain matches your parsed criteria, and/or write the IP address to your .htaccess file using fwrite.
Chella
09-30-2007, 04:10 PM
Hi sjplat,
I just wanted to post this and get your opinion, since you're very adept with PHP. I have the following that I'm going to include.
<?
$blockip = array("192.169.1.1");
$x = count($blockip);
for ($y = 0; $y < $x; $y++) {
if ($REMOTE_ADDR == $blockip[$y]) {
echo ("Site Down");
Exit;}
}
?>
But, I'm unsure of how to block the resolved DNS information I received (crchtx.sbcglobal.net) ... am I doing this correctly?
SiriusB
09-30-2007, 04:36 PM
I don't know the answer to your question, but I do have an improvement on your code: Change in bold
<?
$blockip = array("192.169.1.1");
for ($x = 0; $x < count($blockip); $x++) {
if ($REMOTE_ADDR == $blockip[$x]) {
echo ("Site Down");
Exit;}
}
?>
Just removes an extra step that isn't needed :)
Chella
09-30-2007, 04:38 PM
Thanks! :)
sjlplat
09-30-2007, 04:48 PM
Give me a few minutes and I'll show you what I'm talking about. ;)
SiriusB
09-30-2007, 04:52 PM
Out of idle curiosity - why do you want to block this person so much? :p
sjlplat
09-30-2007, 05:14 PM
Here's a PHP code that will allow you to ban users based on certain hostname criteria:
<?
// List the criteria for the first part of the hostname in this array
$ban1 = array(
'crchtx',
'blah'
);
// List the criteria for the second part of the hostname in this array
$ban2 = array(
'sbcglobal',
'blah'
);
// List the criteria for the third part of the hostname in this array
$ban3 = array(
'net',
'com',
'org'
);
// Create an array for the hostname
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$array = explode(".", $hostname);
$count = count($array);
// Compare the hostname array to the ban criteria
for ($i = 0; $i <= $count; $i++) {
if (in_array($array[$i], $ban1) || in_array($array[$i], $ban2) || in_array($array[$i], $ban3)) {
$ban++;
}
}
// If all 3 parts of the hostname ARE listed in the ban arrays, DO NOT allow the visitor to view the page content
if ($ban >= 3) {
exit("You are banned!");
}
?>
Chella
09-30-2007, 06:05 PM
Wow, that's amazing. I'm going to give it a go. Thanks for all of your help.
sjlplat
09-30-2007, 06:22 PM
Wow, that's amazing. I'm going to give it a go. Thanks for all of your help.
This is a very basic script, but it will do the job. You can expand on it by writing to and retrieving data from a database or flat files. I would personally create a flat file with all the addresses you want to ban. You can then cross reference the flat file with the visitor's hostname.
shadmego
09-30-2007, 07:35 PM
I wonder if it would be possible to ban someone based on their mac address. Yes, it can be spoofed, but it is quite difficult and tedeous to do so.
Anyone out there know about this? I've looked for a few days and can't find anything except wireless and switch technology that will filter based on mac addresses ....
SiriusB
09-30-2007, 08:00 PM
Not possible really.
For a start, MAC addresses aren't sent in HTTP headers, so you couldn't access it directly through PHP [or any other language]. There are commands in Linux to find the MAC of an IP but it would only work if you were on the same network.
Reason being that there will be a multitude of devices between the webserver and the person you want to ban. Each device replaces the MAC address in the packet. So even if you did get the MAC [unlikely] you'd end up banning a router somewhere :p
shadmego
09-30-2007, 09:02 PM
:o Yeah ... after I screwed my head back on, and after I asked the question, I realized the MAC is changed after every hop.
I honestly can't believe I spent so much time on that. I suppose the simple things escape everyone once in a while.
Thanks for helpin me screw my head back on ...:o
~regards,
Shadmego
SiriusB
10-01-2007, 07:25 AM
Well it is a good idea... the multitude of problems aside :D
imobipt
01-08-2008, 07:31 PM
Hello
Can you guys help meon something ...
Iīm trying to block some ip adresses of several concorrent agencies in my area because they are copying my prices to his products and thatīs not fair.
I would like to block dynamic acess and static ip of his computers.
Thank s
sjlplat
01-08-2008, 10:53 PM
You'll have to find out which IP blocks they own.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.