Storing/Querying IP

I am not able to give a direct answer. But see if this discussion (and the stackoverflow link there) can help you. Various techniques are discussed. Ip ranges/CIDR