Skip to content

Instantly share code, notes, and snippets.

@gcmurphy
Created August 14, 2022 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcmurphy/cdc5a3e69d0edfa56978cd9068ce7de5 to your computer and use it in GitHub Desktop.
Save gcmurphy/cdc5a3e69d0edfa56978cd9068ce7de5 to your computer and use it in GitHub Desktop.
check if ip address in fastly public address block
import argparse
import requests
import ipaddress
import sys
parser = argparse.ArgumentParser(description="checks if ip address in fastly ip range")
parser.add_argument("ip", metavar='IP', type=ipaddress.IPv4Address, nargs='+',
help="ip addresses to check")
args = parser.parse_args()
response = requests.get("https://api.fastly.com/public-ip-list").json()
for network_range in response["addresses"]:
network = ipaddress.ip_network(network_range)
for ip in args.ip:
if ip in network:
print(f"{ip} in fastly network: {network}")
sys.exit(1)
print(f"{ip} not in fastly public address block")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment