Created
May 25, 2021 05:47
-
-
Save fukasawah/a12cb288f7f332484e3053d76daa09fd to your computer and use it in GitHub Desktop.
Azure IP Check script sample
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
# ### Usage ### | |
# mkdir data | |
# az account list-locations --query "[].name" --output tsv | tr -d "\r" | while read region; do az network list-service-tags --location "$region" > "data/list-service-tags-${region}.json"; done; | |
# python ip-check.py "data/list-service-tags-japaneast.json" "10.0.0.1" | |
import sys | |
import ipaddress | |
import json | |
if len(sys.argv) < 2: | |
print("usage) python prog.py list-service-tags.json IP") | |
exit(1) | |
arg_jsonpath = sys.argv[1] | |
arg_target_ip = sys.argv[2] | |
with open(arg_jsonpath) as fp: | |
data = json.load(fp) | |
target_ip = ipaddress.ip_address(arg_target_ip) | |
for val in data["values"]: | |
for prefix in val["properties"]["addressPrefixes"]: | |
network = ipaddress.ip_network(prefix) | |
if target_ip in network: | |
print(f'prefix={network}, name={val["name"]}, region={val["properties"]["region"] or "unknown"}, networkFeatures={val["properties"]["networkFeatures"]}, state={val["properties"]["state"]}') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment