Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>/* your base data */ $domains = array(/* your data */); /* a list of domains per ip number, like $domain_by_ip['64.34.119.12'] = 'stackoverflow.com' */ $domain_by_ip = array(); /* a list counting number of domains by ip number */ $ip_count = array(); /* a list of domains we faild to fetch ip number for */ $failed = array(); /* loop through all doains */ foreach($domains as $current_domain) { /* fetch the A record for all domains */ $current_dns_record = dns_get_record($current_domain, DNS_A); /* if there is a dns record */ if($current_dns_record) { /* fetch ip from result */ $current_ip = $current_dns_record[0]['ip']; /* thos row is not needed, but php may triggering a warning oterhwise */ if(!isset($domain_by_ip[$current_ip])) $domain_by_ip[$current_ip] = array(); if(!isset$ip_count[$current_ip])) $ip_count[$current_ip] = array(); /* add domain to the list by ip */ $domain_by_ip[$current_ip][] = $current_dns_record; /* count up the count of domains on this ip */ $ip_count[$current_ip]++; } else { /* if there was no dns record, put this domain on the fail list */ $failed[] = $current_domain; } } /* create a list for storing batches */ $batches = array(); /* as long as we have ip-numbers left to use */ while($ip_count) { /* create a list for storing current batch */ $current_batch = array(); /* sort ip-numbers so we take the ip-numbers whit most domains first */ arsort($ip_count); /* take the top 5 ip-numbers from the list */ $current_batch_ip_list = array_slice(array_keys($ip_count), 0, 5); /* foreach of thous 5 ip-numbers .. */ foreach($current_batch_ip_list as $current_ip) { /* move one domain from the domain by ip list to the current batch */ $current_batch[] = array_pop($domain_by_ip[$current_ip]); /* count down the numbers of domains left for that ip */ $ip_count[$current_ip]--; /* if there is no more domains on this ip, remove it from the list */ if($ip_count[$current_ip] == 0) { unset($ip_count[$current_ip]); } } /* add current batch to the list of batches */ $batches[] = $current_batch; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload