Wednesday, January 21, 2015

Mikrotik Netflix Selective Routing


If y'all alive inward a province without Netflix, y'all are forced to role a VPN to larn Netflix access. Unfortunately at that spot is no slow agency to road Netflix traffic exclusively. The scripts below volition assistance to construct an address listing of IP's to road through the tunnel. It should function alongside whatever VPN provider


Please authorities notation that these scripts are really cpu intensive, I tend to run them for a twenty-four hr catamenia or so, in addition to hence I switch them off.

They function yesteryear analyzing the DNS cache inward lodge to practise the road list, in addition to since about of the domains bring really brusque conk times, they need to run often. You bring to role the mikrotik every bit your network DNS server.

Under System->Scripts practise the next scripts, they volition search through the Mikrotik DNS cache, looking for Netflix entries, in addition to add together them to the address list.:

Name: NetflixDNS
Content:
:local myServers { "nflx";"nflximg";"unodns";"uno"}
/ip dns cache all {
  :foreach i in=$myServers do={
    :foreach j in=[find where (name $i)] do={
      :local myName [get $j name]
      :local myType [get $j type]
      :local myData [get $j data]
   
      :if ($myType = "A") do={
         :if ([/ip road notice dst-address="$myData/32"] != "") practise {:log information "Route $myData exists, skipping."} else {
         /ip road add together dst-address=$myData gateway=NetflixTunnel comment="Netflix DNS-Name=$myName"
        }
       }
##CNAME
      :if ($myType = "CNAME") do={
                :local currentName $j
                :local nextName [find where (name=$myData && type="CNAME")]
                :local startName $myName
                :while ($nextName != "") do={
                    :set currentName $nextName
                    :set nextName [find where (name=[get $nextName data] && type="CNAME")]
                }

                :resolve [get $currentName data]
                :set startName [get $currentName name]
                :foreach k in=[find where (name=[get $currentName data] && type="A")] do={
                    :set myData [get $k data]
                    :set myName [get $k name]
:do {
  :if ([/ip road notice dst-address="$myData/32"] != "") practise {:log information "Route $myData exists, skippings."} else {
  /ip road add together dst-address=$myData gateway=NetflixTunnel comment="Netflix-DNS-Name=$startName CNAME=$myName"
                                                                                  :log information "CNAME ADDED"
}
                }
                }
            }
      }

###END CNAME
 
}}
/ip dns cache flush
:log information "Completed"

Once y'all bring created the script, y'all need to become in addition to schedule it nether System->Scheduler

Name: Netflix DNS Lookups
Start Date: Startup
Start Time: 00:00:00
Interval: 00:00:30 (you tin brand this lower if your Routerboard tin grip it)
On Event:
/system script run NetflixDNS


That's it, y'all should instantly hold upward able to savor Netflix, without having all your mesh traffic running through the tunnel.

Let me know inward the comments if y'all bring whatever ideas on how to amend the script, or if y'all notice whatever bugs.