phporcaffeine Posted December 10, 2008 Share Posted December 10, 2008 Okay, I have a list of various ip address that are not in any particular order or form any particular subnet ... think of them as just random addresses. Here is a sample: 193.122.140.196 193.122.140.192 212.209.042.128 193.132.159.000 203.166.028.064 156.070.222.001 218.104.051.160 194.034.064.001 194.034.065.001 194.034.066.001 194.034.067.001 199.068.016.000 067.111.075.099 212.044.025.206 212.044.008.034 195.102.024.074 193.122.140.207 212.209.042.135 193.132.159.255 203.166.028.127 156.070.222.255 218.104.051.174 Now I need to iterate over this list "somehow" to identify and group together, like addresses so I can express them by ranges. For example: 193.122.140.207 and 193.122.159.255 would be expressed as 193.122.*.* 193.122.140.20 and 193.122.140.80 would be expressed as 193.122.140.20-80 I don't seem to be able to figure out how I would logically do it? Any help or ideas? Thanks in advance Quote Link to comment Share on other sites More sharing options...
gevans Posted December 10, 2008 Share Posted December 10, 2008 Can you give me an example of how that list would look after you output it?? your example showed 2 different ways of parsing the ip's Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 10, 2008 Share Posted December 10, 2008 Yeah, you definitely need to provide more details. If you were to combine the two examples you posted what would the result be: - 193.122.140.207 - 193.122.140.20 - 193.122.140.80 - 193.122.159.255 Would it be - 193.122.140.20-207 - 193.122.159.255 Or just: - 193.122.*.* I would start by putting all of the IPs into multiple-dimensional arrays with each octet as a separate array element. Then sort by each octet. You would them have them in a logincal order to process - once you have clear rules for processing them. Quote Link to comment Share on other sites More sharing options...
msinternet Posted December 10, 2008 Share Posted December 10, 2008 First step has to be putting them in an array and sorting them. Next I guess you would loop through and apply rules but we need more info on these. Martin Quote Link to comment Share on other sites More sharing options...
Caesar Posted December 10, 2008 Share Posted December 10, 2008 If I understood..... <?php function FormatIP($IP) { if(preg_match('/[0-9]+\.[0-9]+\.[0-9]+\.[0-9][0-9][0-9]/',$IP)) { $ip = preg_replace('/([0-9]+\.)([0-9]+\.)([0-9]+\.)([0-9]+)/','\\1\\2*.*',$IP); } else { $ip = str_replace(' ','',preg_replace('/([0-9]+\.)([0-9]+\.)([0-9]+\.)([0-9]+)/','\\1\\2\\3 20-80',$IP)); } return $ip; } //$ip = '192.168.0.100'; <-- This will return 192.168.*.* //$ip = '192.168.0.10'; <-- This will return 192.168.0.20-80 $p = FormatIP($ip); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.