Strahan Posted March 13, 2009 Share Posted March 13, 2009 Howdy. I have a database that has a list of "targets". Computer names, user names and IP addressing. If the current system that the script runs on matches the database for one of those targets, it runs that record. Now the computer & user names I have working fine. The IP I used to have working, but I hit a roadblock. I wanted to be able to do wildcards, like grab all IPs in specific subnets. I made it able to accept an IP like 192.168.0.* for example. However, I neglected to take into account small subnetted ranges.. like 192.168.1.192 with a CIDR of /28. That means only .192 - .207 would fall within that network. Soooo... I have fields like this in the database: 192.168.1.192/28 10.0.0.102/32 ..and the script knows that my current IP for example is 192.168.1.195. Short of looping through every single record that has an IP and testing it against my current IP, is there an efficient way to match an IP to a network designation like that? Link to comment https://forums.phpfreaks.com/topic/149279-need-help-figuring-out-how-to-query-data-efficiently/ Share on other sites More sharing options...
fenway Posted March 15, 2009 Share Posted March 15, 2009 Well, since it's easy to figure out what IP range is covered by the CIDR, assuming you stored IPv4 as UNSIGNED INT, this should be trivial with a BETWEEN. Link to comment https://forums.phpfreaks.com/topic/149279-need-help-figuring-out-how-to-query-data-efficiently/#findComment-785156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.