Created
August 14, 2022 03:29
-
-
Save gcmurphy/cdc5a3e69d0edfa56978cd9068ce7de5 to your computer and use it in GitHub Desktop.
check if ip address in fastly public address block
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 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