How to search an IP in an IP range using PHP? -


i have 1000 ip address. calculate ip ranges them using bellow code:

public function iprange($mainip, $mask) {     $mainiplong = ip2long($mainip);     $masklong = ip2long($mask);      $netid = long2ip($mainiplong & $masklong);     $broadcast = long2ip($mainiplong | ~$masklong);      //here insert $netid , $broadcast mysql table     //so have abount 1000 records } 

it calculates ip range correctly, example if call this:

iprange('91.99.98.243', '255.255.255.240'); 

result be:

$netid     -> 91.99.98.240 $broadcast -> 91.99.98.255 

now need have search function. should find sub-range given ip address, if call search('91.99.98.249'), search() function should show record netid 91.99.98.240 , broadcast field 91.99.98.255.

how can that?

function find($ip){ //get $netid , $bcast db 1 one //loop through records if(ip2long($ip)>=ip2long($netid) && ip2long($ip)<=ip2long($bcast) ){ echo $netid; echo $bcast; }  } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -