Skip to content

Instantly share code, notes, and snippets.

@47star
Created August 15, 2023 09:48
Show Gist options
  • Save 47star/aea653e25a77b4274eb3554dd738b7ff to your computer and use it in GitHub Desktop.
Save 47star/aea653e25a77b4274eb3554dd738b7ff to your computer and use it in GitHub Desktop.
Fetch IPv4 blocks of googleusercontent.com
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