Skip to content

Instantly share code, notes, and snippets.

@touhonoob
Created August 23, 2014 17:34
Show Gist options
  • Save touhonoob/555addfb7a96dfa08e07 to your computer and use it in GitHub Desktop.
Save touhonoob/555addfb7a96dfa08e07 to your computer and use it in GitHub Desktop.
Extract Google IP CIDRs
<?php
$blocks = [];
$result = shell_exec("nslookup -q=TXT _spf.google.com 8.8.8.8");
preg_match_all("%include:(.+?) %", $result, $matches, PREG_SET_ORDER);
foreach($matches as $block) {
$blocks[] = $block[1];
}
print_r($blocks);
$ips = [];
foreach($blocks as $block) {
$result = shell_exec("nslookup -q=TXT $block 8.8.8.8");
preg_match_all("%ip4:(.+?) %", $result, $matches, PREG_SET_ORDER);
foreach($matches as $match) {
$ips[] = $match[1];
}
}
foreach($ips as $ip) {
echo "set_real_ip_from $ip;\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment