Hi,

I want to compare an IP I have (one that I know belongs to Inktomi for example), to an IP from a visitor to my site.

My problem is that some (most search engines) visitors have a whole IP Range... and I can't figure out how to compare the IP I have , to the IP Range... or the other way around.

I have:

$tmp_ip="66.196.64.255";
// IP range is [66.196.64.0 - 66.196.127.255]
if ($tmp_ip=="66.196.[6-9][4-9]|1[0-1][0-9]|12[0-7].[0-9]|1[0-9][0-9]|2[0-5][0-5]") {
echo "Inktomi"; // Inktomi SE
} else {
echo "Not sure";
}

    Hiya, easiest way that I can think of to do this would be to split them up into an array, and check that the provided IP is between the number range.

    <?php
    
    // IP Range: 192.168.0.1 - 192.168.12.255
    // Provided IP: 192.168.11.196
    
    $IPStart = explode(".", "192.168.0.1");
    $IPFinish = explode(".", "192.168.12.254");
    $IPProv = explode(".", "192.168.11.196");
    $Between = true;
    
    for($i = 0; $i < 4; $i++) {
    
    	if($IPStart[$i] > $IPProv[$i] || $IPFinish[$i] < $IPProv[$i]) {
    
    		$Between = false;
    	}
    }
    
    if($Between !== false) {
    
    	echo "Match";
    } else {
    
    	echo "No Match!";
    }
    
    ?>

      Thanks alot, that seems to do the trip.

        Write a Reply...