MS Azure - automatically downloads the latest ip ranges used by MS Azure Datacenters

I see that MS provides a website ( http://www.microsoft.com/EN-US/DOWNLOAD/DETAILS.ASPX?ID=41653 ) where you can download the public ip ranges used by MS Azure.

The question is, is there a way to download the XML file from this site automatically using Python or other scripts? I am trying to schedule a task to capture a new IP range file and process it for my firewall policies.

Thank,

+4
source share
1 answer

wget scriptNameYouWant.sh bash script, XML .

#! /bin/bash
wget http://download.microsoft.com/download/0/1/8/018E208D-54F8-44CD-AA26-CD7BC9524A8C/PublicIPs_21050223.xml

, .

Python, :

, scriptNameYouWant.py :

import urllib2
page = urllib2.urlopen("http://download.microsoft.com/download/0/1/8/018E208D-54F8-44CD-AA26-CD7BC9524A8C/PublicIPs_21050223.xml").read()
f = open("xmlNameYouWant.xml", "w")
f.write(str(page))
f.close()

python bash, , , python, bash.

xml, url, curl. :

#! /bin/bash
FIRSTLONGPART="http://download.microsoft.com/download/0/1/8/018E208D-54F8-44CD-AA26-CD7BC9524A8C/PublicIPs_"
INITIALURL="http://www.microsoft.com/EN-US/DOWNLOAD/confirmation.aspx?id=41653"
OUT="$(curl -s $INITIALURL | grep -o -P '(?<='$FIRSTLONGPART').*(?=.xml")'|tail -1)"
wget -nv $FIRSTLONGPART$OUT".xml"

, , .

+1

All Articles