Created
June 11, 2021 08:09
-
-
Save ronniejoshua/02cf265685a86b5c4b3751c7baa89099 to your computer and use it in GitHub Desktop.
Python code to whitelist External IP for GCP Compute Engine Firewall Rules
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 requests | |
import os | |
def gcp_firewall_ip_whitelisting(): | |
my_external_ip = requests.get("https://api.ipify.org").text | |
print(f"My External IP Address: {my_external_ip}") | |
known_ip_addresses = "" | |
cmd_to_run = f"gcloud compute firewall-rules update nc-de-doc-sec --source-ranges {my_external_ip}, {known_ip_addresses}" | |
os.system(cmd_to_run) | |
if __name__ == "__main__": | |
gcp_firewall_ip_whitelisting() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment