rem_lex

Mikrotik resolve-block-hosts

Apr 29th, 2020
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. # define variables
  2. :local list
  3. :local comment
  4. :local newip
  5.  
  6. # Loop through each entry in the address list.
  7. :foreach i in=[/ip firewall address-list find list="blocked-site" disabled=no] do={
  8.  
  9. # Get the comment for this address list item (this is the host name to use)
  10. :set comment [/ip firewall address-list get $i comment]
  11.  
  12. # Resolve it and set the address list entry accordingly.
  13. :log info "dns resolve $comment"
  14. :do {
  15. ## :set newip [:resolve $comment]
  16. :if ( [:len [/ip firewall address-list find list="blocked-host" address=$newip]] = 0 ) do={
  17. ## :log info " $comment = $newip"
  18. /ip firewall address-list add address=$newip list=blocked-host comment=$comment
  19. }
  20. } on-error={
  21. :log error "dns normal resolve failure $comment"
  22. }
  23.  
  24. #Resolve by google DNS
  25. :do {
  26. :set newip [:resolve $comment server=8.8.8.8]
  27. :if ( [:len [/ip firewall address-list find list="blocked-host" address=$newip]] = 0 ) do={
  28. # :log info " $comment = $newip"
  29. /ip firewall address-list add address=$newip list=blocked-host comment=$comment
  30. }
  31. } on-error={
  32. :log error "dns google resolve failure $comment"
  33. }
  34. }
  35.  
  36. #####
  37. /ip fi ad
  38. add address=0.0.10.15 comment=example.com list=blocked-site
  39. add address=0.0.10.16 comment=example.net list=blocked-site
Advertisement
Add Comment
Please, Sign In to add comment