Created
August 15, 2023 09:48
-
-
Save 47star/aea653e25a77b4274eb3554dd738b7ff to your computer and use it in GitHub Desktop.
Fetch IPv4 blocks of googleusercontent.com
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
import re | |
from scapy.all import * | |
from scapy.layers.dns import DNS, DNSQR | |
from scapy.layers.inet import IP, UDP | |
def query(n, t="TXT"): | |
return sr1( | |
IP(dst="8.8.8.8") / UDP(dport=53) / DNS(rd=1, qd=DNSQR(qname=n, qtype=t)), | |
verbose=False, | |
)[DNS] | |
google = "_cloud-netblocks.googleusercontent.com" | |
netblocks = re.findall("include:([^ ]+)", str(query(google).an.rdata)) | |
ips = [ip for nb in netblocks for ip in re.findall("ip4:([^ ]+)", str(query(nb).an.rdata))] | |
print(",".join(ips)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment