Last active
September 2, 2018 18:13
-
-
Save katsube/3319f0a160574d18e91e2624dfd4b001 to your computer and use it in GitHub Desktop.
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 | |
/* | |
* [CLI] Create IP address list of request source of Google Apps Script | |
* | |
* Copyright (C) 2018 M.Katsube | |
* This software is released under the MIT License. | |
* http://opensource.org/licenses/mit-license.php | |
*/ | |
define('START_DOMAIN', '_cloud-netblocks.googleusercontent.com'); | |
$hosts = getDomains(START_DOMAIN); | |
foreach($hosts as $host){ | |
echo implode("\n", getIP($host)); | |
echo "\n"; | |
} | |
/** | |
* Retrieve domain list of SPF records | |
* | |
* @param {string} $start | |
*/ | |
function getDomains($start){ | |
$result = []; | |
$buff = getDNSRecord($start, DNS_TXT); | |
foreach( explode(' ', $buff[0]['txt']) as $host ){ | |
if( preg_match('/^include:([0-9a-zA-Z\.\-_]{1,})$/', $host, $match) ){ | |
array_push($result, $match[1]); | |
} | |
} | |
return($result); | |
} | |
/** | |
* Create IP address list | |
* | |
* @param {string} $domain | |
*/ | |
function getIP($domain){ | |
$result = []; | |
$buff = getDNSRecord($domain, DNS_TXT); | |
foreach( explode(' ', $buff[0]['txt']) as $host ){ | |
if( preg_match('/^ip4:([0-9\.\/]{1,})$/', $host, $match) ){ | |
array_push($result, $match[1]); | |
} | |
} | |
return($result); | |
} | |
/** | |
* Get DNS record | |
* | |
* @param {string} $domain | |
* @param {integer} $option DNS_A, DNS_CNAME, DNS_HINFO, DNS_CAA, DNS_MX, DNS_NS, DNS_PTR, DNS_SOA, DNS_TXT, DNS_AAAA, DNS_SRV, DNS_NAPTR, DNS_A6, DNS_ALL DNS_ANY | |
*/ | |
function getDNSRecord($domain, $option){ | |
$buff = dns_get_record($domain, $option); | |
if( $buff === false || count($buff) === 0 ){ | |
echo "[ERROR] Can not GET DNS Record: $domain\n"; | |
exit; | |
} | |
return($buff); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment