Network Calculator Or Firewall

Hi everyone.

I need extension or component that calculates network ip subnets to be used in a kind of firewall.

I want to put some network in configuration like “192.168.0.1/24” or “192.168.0.1/255.255.255.0”, for instance, and when someone comes with ip 192.168.0.22, it should define that client’s ip belongs to this subnet and then do action I want.

Are there any ready solutions, or at least ip calculator for Yii?

Thank you in advance.