User Tools

Site Tools


ips_office_365_to_proxy.pac_with_regex

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
ips_office_365_to_proxy.pac_with_regex [2019/02/18 14:26]
ips_office_365_to_proxy.pac_with_regex [2019/02/18 14:26]
admin
Line 1: Line 1:
 +**How to fill IPs office 365 to proxy.pac with regex**
  
 +1/ You need IPs of your service : [[https://​support.office.com/​fr-fr/​article/​URL-et-plages-d-adresses-IP-Office-365-8548a211-3fe7-47cb-abb1-355ea5aa88a2|microsoft.support]]
 +
 +2/ Need this site with __**python encode**__ : [[https://​regex101.com/​|regex101.com/​]]
 +
 +3/ Need netmask
 +<file txt netmask.txt>​
 +Netmask: ​  ​128.0.0.0 = 1
 +Netmask: ​  ​192.0.0.0 = 2
 +Netmask: ​  ​224.0.0.0 = 3
 +Netmask: ​  ​240.0.0.0 = 4
 +Netmask: ​  ​248.0.0.0 = 5
 +Netmask: ​  ​252.0.0.0 = 6
 +Netmask: ​  ​254.0.0.0 = 7
 +Netmask: ​  ​255.0.0.0 = 8
 +Netmask: ​  ​255.128.0.0 = 9
 +Netmask: ​  ​255.192.0.0 = 10
 +Netmask: ​  ​255.224.0.0 = 11
 +Netmask: ​  ​255.240.0.0 = 12
 +Netmask: ​  ​255.248.0.0 = 13
 +Netmask: ​  ​255.252.0.0 = 14
 +Netmask: ​  ​255.254.0.0 = 15
 +Netmask: ​  ​255.255.0.0 = 16
 +Netmask: ​  ​255.255.128.0 = 17
 +Netmask: ​  ​255.255.192.0 = 18
 +Netmask: ​  ​255.255.224.0 = 19
 +Netmask: ​  ​255.255.240.0 = 20
 +Netmask: ​  ​255.255.248.0 = 21
 +Netmask: ​  ​255.255.252.0 = 22
 +Netmask: ​  ​255.255.254.0 = 23
 +Netmask: ​  ​255.255.255.0 = 24
 +Netmask: ​  ​255.255.255.128 = 25
 +Netmask: ​  ​255.255.255.192 = 26
 +Netmask: ​  ​255.255.255.224 = 27
 +Netmask: ​  ​255.255.255.240 = 28
 +Netmask: ​  ​255.255.255.248 = 29
 +Netmask: ​  ​255.255.255.252 = 30
 +Netmask: ​  ​255.255.255.254 = 31
 +Netmask: ​  ​255.255.255.255 = 32
 +</​file>​
 +
 +4/Make the dictionary ​
 +
 +<sxh regex>
 +Dictionary:​1=128.0.0.0:​2=192.0.0.0:​3=224.0.0.0:​4=240.0.0.0:​5=248.0.0.0:​6=252.0.0.0:​7=254.0.0.0:​8=255.0.0.0:​9=255.128.0.0:​10=255.192.0.0:​11=255.224.0.0:​12=255.240.0.0:​13=255.248.0.0:​14=255.252.0.0:​15=255.254.0.0:​16=255.255.0.0:​17=255.255.128.0:​18=255.255.192.0:​19=255.255.224.0:​20=255.255.240.0:​21=255.255.248.0:​22=255.255.252.0:​23=255.255.254.0:​24=255.255.255.0:​25=255.255.255.128:​26=255.255.255.192:​27=255.255.255.224:​28=255.255.255.240:​29=255.255.255.248:​30=255.255.255.252:​31=255.255.255.254:​32=255.255.255.255
 +</​sxh>​
 +
 +
 +5/Regex
 +
 +<sxh python>
 +(?​s)(\d{1,​3})\.(\d{1,​3})\.(\d{1,​3})\.(\d{1,​3})(/​\b)(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)(?​=.*:​\6=(\w+\.\w+\.\w+\.\w+\b))
 +</​sxh>​
 +
 +
 +6/An example file
 +
 +<file txt example.txt>​
 +23.103.132.0/​22
 +23.103.136.0/​21
 +23.103.144.0/​20
 +23.103.198.0/​23
 +40.92.0.0/​14
 +
 +Dictionary:​1=128.0.0.0:​2=192.0.0.0:​3=224.0.0.0:​4=240.0.0.0:​5=248.0.0.0:​6=252.0.0.0:​7=254.0.0.0:​8=255.0.0.0:​9=255.128.0.0:​10=255.192.0.0:​11=255.224.0.0:​12=255.240.0.0:​13=255.248.0.0:​14=255.252.0.0:​15=255.254.0.0:​16=255.255.0.0:​17=255.255.128.0:​18=255.255.192.0:​19=255.255.224.0:​20=255.255.240.0:​21=255.255.248.0:​22=255.255.252.0:​23=255.255.254.0:​24=255.255.255.0:​25=255.255.255.128:​26=255.255.255.192:​27=255.255.255.224:​28=255.255.255.240:​29=255.255.255.248:​30=255.255.255.252:​31=255.255.255.254:​32=255.255.255.255
 +</​file>​
 +
 +
 +7/Select the "​subsitution"​ box
 +An put 
 +<sxh python>
 +isInNet(host,"​$1.$2.$3.$4","​$7"​)||
 +OR
 +isInNet(host,"​\1.\2.\3.\4","​\7"​)||
 +</​sxh>​
 +
 +
 +8/ The result is 
 +<sxh python>
 +isInNet(host,"​23.103.132.0","​255.255.252.0"​)||
 +isInNet(host,"​23.103.136.0","​255.255.248.0"​)||
 +isInNet(host,"​23.103.144.0","​255.255.240.0"​)||
 +isInNet(host,"​23.103.198.0","​255.255.254.0"​)||
 +isInNet(host,"​40.92.0.0","​255.252.0.0"​)||
 +</​sxh>​
 +
 +
 +10/ You just need to add some code for work with proxy.pac
 +<file txt proxy.pac>​
 +function FindProxyForURL(url,​ host) {
 +
 +//example of redirect
 +if (
 +isInNet(host,"​23.103.132.0","​255.255.252.0"​)||
 +isInNet(host,"​23.103.136.0","​255.255.248.0"​)||
 +isInNet(host,"​23.103.144.0","​255.255.240.0"​)||
 +isInNet(host,"​23.103.198.0","​255.255.254.0"​)||
 +isInNet(host,"​40.92.0.0","​255.252.0.0"​)
 +)return "​DIRECT";​
 +
 +
 +      return "PROXY YOURPROXY.XXX:​8080;​ DIRECT";​
 +   }
 +</​file>​
 +
 +
 +9/ Screenshots
 +
 +{{:​fortigate:​regex_network_mask01.jpg?​800|}}
 +{{:​fortigate:​regex_network_mask02.jpg?​800|}}
 +
 +----
 +
 +Source : don't remember
 +
 +----
 +- created date : 2017.09.20 -
ips_office_365_to_proxy.pac_with_regex.txt ยท Last modified: 2019/02/18 14:26 (external edit)