# Script to add Youtube IP addresses into address list # Tested with Mikrotik 6.48 :local LISTNAME "youtube" # Timeout for each list :local ListTimeout "30d" # Name of website to be added to address list :local TARGET1 "youtube.com" :local TARGET2 "googlevideo.com" :local TARGET3 "ytimg.com" :local TARGET4 "youtu.be" :local TARGET5 "youtube-ui.l.google.com" # when site is visited for the first time add ip of site to address list if not listed :if ( [/ip firewall address-list find where list=$LISTNAME] = "") do={ :log warning "No address list for $TARGET1 and $TARGET2 found ! creating and adding resolved entry for 1st time usage โ€ฆ gate" /ip firewall address-list add list=$LISTNAME address=[:resolve $TARGET1] comment=$TARGET1 timeout=$ListTimeout /ip firewall address-list add list=$LISTNAME address=[:resolve $TARGET2] comment=$TARGET2 timeout=$ListTimeout /ip firewall address-list add list=$LISTNAME address=[:resolve $TARGET3] comment=$TARGET3 timeout=$ListTimeout /ip firewall address-list add list=$LISTNAME address=[:resolve $TARGET4] comment=$TARGET4 timeout=$ListTimeout /ip firewall address-list add list=$LISTNAME address=[:resolve $TARGET5] comment=$TARGET5 timeout=$ListTimeout } else={ :log warning "Previous List for $LISTNAME found ! moving forward and checking if DNS entries can be added in it โ€ฆ" } # Check DNS entries for names matching websites :foreach i in=[/ip dns cache all find where (name~"$TARGET1" || name~"$TARGET2" || name~"$TARGET3" || name~"$TARGET4" || name~"$TARGET5") && (type="A") ] do={ # Get IP Address from the names for hold in temporary buffer :local Buffer [/ip dns cache get $i data]; delay delay-time=10ms # Check if entry already exists in address list, otherwise add :if ( [/ip firewall address-list find where address=$Buffer] = "") do={ # Fetch DNS names for the entries :local sitednsname [/ip dns cache get $i name] ; # Print name in LOG window :log info ("added entry: $sitednsname $Buffer"); # Add IP addresses and sitename names to the address list /ip firewall address-list add address=$Buffer list=$LISTNAME comment=$sitednsname timeout=$ListTimeout; } }