PHP has a set of predefined variables, one of them is the variable $REMOTE_ADDR
this tells you the IP address of the remote machine. You can just explode the string into 4 sections (seperated by the '.') and make sure the first 3 sections meet your requirements.