View Single Post
  #4 (permalink)  
Old 09-30-2008, 04:37 PM
wige's Avatar
wige wige is offline
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,629
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: I am looking for a PHP algorithm/script

Just trying to work through the logic of this...

If I understand correctly, your database consists of the right column, listing the range of IP numbers for that block. What you need to do is on export convert that to the dot form (IPv4) plus calculate the proper subnet mask for the range so you are returning the left column? This should be doable with the built in converter functions long2ip and ip2long that are part of PHP.

Basically, I think you would just need to do the conversion by exploding the range into two values, min and max and converting the min to an IP address...

$min_ip = long2ip($min_num);

Then, just figure out what the difference between the min and max number is:

$range = $max_num - $min_num;

Then convert that range into the correct subnet:

$mask = <insert some math I don't remember here - sorry - anyone?>

Then concatenate the $min_ip and the mask to get the final string:

$answer = $min_ip . '/' . $mask;
__________________
The best way to learn anything, is to question everything.
Reply With Quote