Last active
December 19, 2016 07:55
-
-
Save clburlison/574d7b36aff53ce628a9621748ce9de5 to your computer and use it in GitHub Desktop.
Go use this instead: https://github.com/pbowden-msft/OfficeCDNCheck
This file contains hidden or 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
| #!/usr/bin/python | |
| """ | |
| Go use this instead: https://github.com/pbowden-msft/OfficeCDNCheck | |
| A script to help determine which CDN you're client is talking to for | |
| Microsoft Office 2016 updates. | |
| Author: Clayton Burlison <https://clburlison.com> | |
| Date Modifed: Sept. 14th, 2016 | |
| Much code stolen from AutoPkg | |
| https://github.com/autopkg/recipes/blob/master/MSOfficeUpdates/MSOffice2016URLandUpdateInfoProvider.py | |
| """ | |
| import urllib2 | |
| import plistlib | |
| CULTURE_CODE = "0409" | |
| BASE_URL = "https://officecdn.microsoft.com/pr/%s/OfficeMac/%s15-chk.xml" | |
| PROD_DICT = { | |
| 'Excel': 'XCEL', | |
| 'OneNote': 'ONMC', | |
| 'Outlook': 'OPIM', | |
| 'PowerPoint': 'PPT3', | |
| 'Word': 'MSWD', | |
| } | |
| CHANNELS = { | |
| 'Production': 'C1297A47-86C4-4C1F-97FA-950631F94777', | |
| 'InsiderSlow': '1ac37578-5a24-40fb-892e-b89d85b6dfaa', | |
| 'InsiderFast': '4B2D7701-0A4F-49C8-B4CB-0C2D4043F51F', | |
| } | |
| def connect(url): | |
| """Use urllib2 to request a url and return the componenets.""" | |
| req = urllib2.Request(url) | |
| # Add the MAU User-Agent, since MAU feed server seems to explicitly | |
| # block a User-Agent of 'Python-urllib/2.7' - even a blank User-Agent | |
| # string passes. | |
| req.add_header( | |
| "User-Agent", | |
| "Microsoft%20AutoUpdate/3.6.16080300 CFNetwork/760.6.3 Darwin/15.6.0 (x86_64)") | |
| try: | |
| f = urllib2.urlopen(req) | |
| f_headers = f.info().dict | |
| contents = f.read() | |
| code = f.getcode() | |
| return (code, contents, f_headers) | |
| except urllib2.HTTPError as e: | |
| return (e.code, e.read(), None) | |
| except urllib2.URLError as e: | |
| return (e, None, None) | |
| def tester(channel="Production"): | |
| """This will download each product xml, output the CDN that | |
| your machine is talking at time of connection and which version | |
| the xml contains.""" | |
| for key in PROD_DICT.keys(): | |
| url = BASE_URL % (CHANNELS[channel], | |
| CULTURE_CODE + PROD_DICT[key]) | |
| code, content, headers = connect(url) | |
| if code == 200: | |
| # Our download was sucessful, we should have valid content | |
| # Limit our header to 23 characters so it prints prettier | |
| print("##### {0} ####################".format(key)[:23]) | |
| print("AppID: {0}".format(PROD_DICT[key])) | |
| data = plistlib.readPlistFromString(content) | |
| version = data.get('Update Version', None) | |
| print("Version: {0}".format(version)) | |
| for item in headers.keys(): | |
| if item.lower() == "x-msedge-ref": | |
| cdn = "Azure" | |
| elif item.lower() == "powered-by-chinacache": | |
| cdn = "Powered-By-ChinaCache" | |
| else: | |
| cdn = "Akamai" | |
| print("CDN: {0}".format(cdn)) | |
| else: | |
| print("Error: {0}".format(code)) | |
| tester() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment