On Mon, 18 Mar 2002, Charles Williams wrote: > There will be a form with a text box to allow IP address entries as follows: > > 192.168.5.195 > or > 123.23.35.4 123.23.35.45 123.23.35.74 > or > 123.4.34.1/123.4.34.255 > or > 13.234.5.41/13.234.5.75 12.34.34.150/12.34.34.225 > > The above a just a few examples. I need to be able to grab either the IP > addresses or the ranges and verify that when an IP is entered at a later > date and compared to the above types of previously saved data that the IP is > within the range(s). > > I hope I explained that ok. ;) > > So basically I guess I just need a way of, after retrieving the info from > the DB, splitting the IP (range(s)) apart and then comparing the IP entered > to those in the array(?) to verify that it was a good entry.
It's not exactly clear to me what your question is. But, as to the general question of representing and comparing IP addresses internally, I guess first you'd want to pick a representation that efficiently and flexibly captures the values you expect to work with. Ordinarily I would suggest CIDR subnets but the sample IP addresses you provided do not comply - they seem to be random numbers. Is this because you need to deal with arbitrary sets of IP addresses rather than valid subnets, or because you were just in a hurry while typing your message to the list? Also, I wouldn't recommend using the slash to identify ranges of IP addresses, because the slash already has a specific meaning in this context: the number after it specifies the size of the subnet mask. For instance, to refer to the range 192.168.34.128-192.168.34.135, you'd write 192.168.34.128/29. Anyway, I have a few ideas in mind but with an answer to the above question I'd be able to give you what may be an optimal representation and methodology. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php