How to band range of IP addresses

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Locked
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

How to band range of IP addresses

Post by blackhawk »

After reading the following CMSMS Security page on Banning IP addresses via UDT

http://docs.cmsmadesimple.org/general-i ... ring-cmsms

...is there an enhancement I can place to this code to detect...

{if the user has these first 9 values in their IP address}
..then block that IP address?
{/if}
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: How to band range of IP addresses

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm
Location: Marlow, UK

Re: How to band range of IP addresses

Post by scooper »

If you wanted to extend that UDT to ban a particular ip range from the front end of your site you could just match a substring . So something like:

Code: Select all


$ipaddress = cms_utils::get_real_ip();
if (in_array($ipaddress, $banned))
   die ("You are banned from this website!");

if( substr($ipaddress,0,11)=='111.222.333' ){
   die ("You and all your friends are banned from this website!");
}

If you're planning on doing more than a few simple rules though then this is probably something your firewall should be handling at a sever level.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3492
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: How to band range of IP addresses

Post by velden »

My first thought on this is that blocking by a UDT or in general cmsms/php is generaly not best practice.

Well, it depends on the reason why you want to block those. But I don't think it adds extra security.

I think blocking by firewall or .htaccess or ...(?) is more secure as you don't allow those ip to get to any of the web/php processing.
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

Re: How to band range of IP addresses

Post by blackhawk »

I agree velden,
I am just trying to learn if there is a better way that typing in each IP address one by one, which totally sucks. I need the ability to set a range...

Thanks for that thought
Locked

Return to “The Lounge”