Created
August 23, 2014 17:34
-
-
Save touhonoob/555addfb7a96dfa08e07 to your computer and use it in GitHub Desktop.
Extract Google IP CIDRs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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