Skip to content

Instantly share code, notes, and snippets.

@plambrechtsen
Last active October 18, 2023 20:10
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 plambrechtsen/ca0a08d947c7f5dac6ed85805616105b to your computer and use it in GitHub Desktop.
Save plambrechtsen/ca0a08d947c7f5dac6ed85805616105b to your computer and use it in GitHub Desktop.
Create Cisco ASA Split Tunnel Configuration for WVD based on Azure IP Ranges and Service Tags
import urllib.request
from bs4 import BeautifulSoup
import json
# Retrieve Azure Public URL to find JSON URL in the documnet
azure_public_IP_url = "https://www.microsoft.com/en-us/download/details.aspx?id=56519"
azure_public_IP_url_content = urllib.request.urlopen(azure_public_IP_url).read()
azure_public_IP_url_soup = BeautifulSoup(azure_public_IP_url_content, "html.parser")
azure_wvd_ip = []
# Build CIDR map using loop - Using code found here https://gist.github.com/vndmtrx/dc412e4d8481053ddef85c678f3323a6
subnet_map = {}
for cidr in range(0, 33):
subnet_map.update({str(cidr): ".".join([str((((1 << 32)-1) << (32-cidr) >> cidr_number) & 255) for cidr_number in reversed(range(0, 32, 8))])})
for tag in azure_public_IP_url_soup.find_all(['a']):
# The URL for the JSON URL in the document that needs to be downloaded
if "download.microsoft.com/download/7/1/D/71D86715-5596-4529-9B13-DA13A5DE5B63" in str(tag):
json_content = urllib.request.urlopen(tag['href']).read()
# print(json_content)
azure_public_json = json.loads(json_content)
for value in azure_public_json['values']:
# Find the WVDs in Australia, assuming they are correct
if "WindowsVirtualDesktop.Australia" in value['name']:
azure_wvd_ip += value['properties']['addressPrefixes']
# print(azure_wvd_ip)
# Create network objects with WVD prefix
for wvd_ip in azure_wvd_ip:
ip_split = wvd_ip.split("/")
print(f'object network WVD_{ip_split[0].replace(".","_")}')
print(f' subnet {ip_split[0]} {subnet_map[ip_split[1]]}')
# Create object group
print('object-group network WVD_SPLIT_TUNNEL')
for wvd_ip in azure_wvd_ip:
ip_split = wvd_ip.split("/")
print(f' network-object object WVD_{ip_split[0].replace(".", "_")}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment