in reply to blocking last ip octet

Let MySQL do all the work:
An IP address is simply a 32-bit number. It can be converted to it's numerical equivalent a little like this:
my @octets=split(/\./,$ip_address); my $numerical_address=($octets[3]+(255*$octets[2])+(65535*$octets[1])+ +(16777216*$octets[0]));
Store this in your database as a 32-bit integer, which is much more eficient than an 18-byte character field for IP address.
Then, to see if another IP address is in the same class C, do something like this:
SELECT count(*) from table WHERE (int(ip/256)*256) = (int($ip_address_ +to_be_compared_to/256)*256)
Any result greater than 0 is a hit.
Note that the figure of 256 is for a class C subnet. It can be changed to suit any subnet mask you want to use.
Edit: Oops, that should be 256, not 255.....