MS天青 - 自动下载的MS Azure的数据中心使用了最新的IP范围 [英] MS Azure - automatically download the latest ip ranges used by MS Azure Datacenters
问题描述
我看到MS提供了网站( HTTP:// WWW .microsoft.com / EN-US /下载/ DETAILS.ASPX?ID = 41653 ),在这里你可以下载由MS Azure中使用的公共IP范围。
I see MS has provide website(http://www.microsoft.com/EN-US/DOWNLOAD/DETAILS.ASPX?ID=41653) where you can download the public ip ranges used by MS Azure.
现在的问题是,有没有办法下载从该网站会自动使用Python或其他脚本的XML文件?我想安排一个任务来获取新的IP范围文件,并处理它为我的防火墙策略。
The question is, is there a way to download the XML file from that site automatically using Python or other scripts? I am trying to schedule a task to grab the new IP range file and process it for my firewall policies.
谢谢,
推荐答案
如果你可以使用的wget
写在文本编辑器并将其保存为 scriptNameYouWant.sh
会给你一个bash脚本,下载你想要的XML文件。
if you can use wget
writing in a text editor and saving it as scriptNameYouWant.sh
will give you a bash script that will download the xml file you want.
#! /bin/bash
wget http://download.microsoft.com/download/0/1/8/018E208D-54F8-44CD-AA26-CD7BC9524A8C/PublicIPs_21050223.xml
当然,你也可以直接从终端运行命令并有确切的结果。
Of course, you can run the command directly from a terminal and have the exact result.
如果你想使用Python,一种方式是:
If you want to use Python, one way is:
再次写在文本编辑器,并保存为 scriptNameYouWant.py
的folllowing:
Again, write in a text editor and save as scriptNameYouWant.py
the folllowing:
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虽然好,所以我想有两个蟒蛇或bash一个更优雅的方式。
I'm not that good with python or bash though, so I guess there is a more elegant way in both python or bash.
修改
您尽管使用动态网址卷曲
获取XML。什么工作对我来说是这样的:
You get the xml despite the dynamic url using curl
. What worked for me is this:
#! /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"
同样,我敢肯定有这样做的更优雅的方式。
Again, I'm sure that there is a more elegant way of doing this.
这篇关于MS天青 - 自动下载的MS Azure的数据中心使用了最新的IP范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!