I have recently been working on a project that has seen me pull together a PAC file that helps to separate Office 365 Express Route traffic, Office 365 CDN traffic, internal traffic and general Internet traffic to different proxy servers.
It’s been a complicated process and one of the issues was gathering the necessary URLs that are currently associated with Office 365. Using the script that Aaron Guilmette (https://gallery.technet.microsoft.com/Office-365-Proxy-Pac-60fb28f7) wrote I was able to pull out the URLs that Microsoft published on the official website. However I noticed that this pulled out a lot of duplicate URLs and included references to Facebook, Google, Dropbox and a Hockey website to name a few.
This meant that after using Aaron’s script I had to do some data cleansing for my purposes. So using some of the code from Aaron’s script I have created my own script that pulls out all the relevant URLs from https://support.content.office.net/en-us/static/O365IPAddresses.xml, append the correct start/end to each URL so that it can be utilised within a PAC file. Then the script sorts and removes any duplicates from the list generated from the XML, and also stripes out any references to Facebook, Google, Dropbox
Once the script has completed running you have a complete list of URLs associated with Office 365 and you can then use that information to pull together your PAC file. My script can be found at https://gallery.technet.microsoft.com/Office-365-URL-generator-4fb3d155?redir=0