-
Notifications
You must be signed in to change notification settings - Fork 2
/
Azure-IP-Downloader.ps1
57 lines (42 loc) · 1.82 KB
/
Azure-IP-Downloader.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Azure IP filter and downloader script v1.2.0
# Author: Daniel Keer
# Author URI: https://thedxt.ca
# Script URI: https://github.com/thedxt/IP-Downloader
#
# DESCRIPTION
#
# grabs the JSON file for the Azure IP Ranges and Service Tags – Public Cloud
# script allows for flitering and downloads the ips into one big file
# it also makes a file just for IPv4 and IPv6
#
# change the variables as needed
#save location
$exportlocation = "C:\temp\"
# function to check if save location exists if not create it
function exportloc-check{
if (-not (Test-Path $exportlocation))
{
New-Item -ItemType Directory $exportlocation | out-null
}
}
# run the function
exportloc-check
#region filter
$regionFilter = "canada"
#grab URI from txt file
$LocationURI = Invoke-WebRequest -uri "https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519"
$DLURI = $LocationURI.Links | Where-Object {$_.InnerText -Like "click here to download manually" }
#download the JSON file from MS
$MSjsonDL = Invoke-WebRequest -Uri $DLURI.href
#getting date
$time = get-date -f yyyy_MMM_dd_hhmm_tt
#convert to PS object
$MSjsonOBJ = ConvertFrom-Json $MSjsonDL
#select the values
$properties = $MSjsonOBJ.values.properties
#filter to pick only specific regions and null for ones that dont have regions
$regions = $properties | where-object { $_.region -match $regionFilter -OR $_.region -eq ""}
#save files using reg ex to filter ipv4 and ipv6 to their own files if needed
$regions.addressPrefixes | out-file "$exportlocation\$($time)_filtered_region_$($regionFilter)_all_IPs.txt"
$regions.addressPrefixes -match '\.' | out-file "$exportlocation\$($time)_filtered_region_$($regionFilter)_v4_IPs.txt"
$regions.addressPrefixes -match '\:' | out-file "$exportlocation\$($time)_filtered_region_$($regionFilter)_v6_IPs.txt"