I like AmigoJack's proposal.
We just need to separate an IP by its dot decimal having numbers form 0 to 255 for IPv4 and have ":" hexadecimal for IPv6. Using hexadecimal isn't that hard.
For a number like 'ff' we just need to prepend "0x" forming "0xff" and then ask php to parse it as a integer. In order to be platform independent we must work with 32 bit integers and there is no doubt that 0xffff fits in an integer. So we can have an array of integer with all the parts of the IPv6.
Something like:
- Code: Select all
$ipv6_parts = explode(':', $ipv6);
foreach($ipv6_parts AS $part => $ip)
{
$ipv6_parts[$part] = (int) '0x' . $ip;
}
We could then use something like AmigoJack made to search in the DB and seems like quite straight forward.
I'd also mark the from1, from2, from3, from4, from5, from6, from7, from8 as unique, same for the from. With that both would be indexed and some constraining would be automatically added to prevent duplicates in the from as they are unnecessary.