# Script to add Facebook IP addresses into address list # Tested with Mikrotik 6.48 :local LISTNAME "facebook" # Timeout for each list :local ListTimeout "30d" # Name of website to be added to address list :local TARGET1 "facebook.com" :local TARGET2 "fbcdn.net" # 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 } 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") && (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; } }