返回列表 發帖

help - Mikrotik Script for capture tiktok ip

This script work on only one keyword;
  1. :local sname "tiktok" ;
  2. :local lname "us-only" ;

  3. #/log info ("Starting "$sname" script");
  4. :foreach i in=[/ip dns cache all find where (name~"$sname")] do={
  5.     :local tmpAddress [/ip dns cache get $i name];
  6.    
  7.     :if ( [/ip firewall address-list find where address=$tmpAddress] = "") do={
  8.         :local cacheName [/ip dns cache get $i name] ;
  9.         #/log info ("added entry: $cacheName $tmpAddress");
  10.         /ip firewall address-list add address=$tmpAddress list=$lname timeout=00:01:00 ;
  11.     }
  12. }
  13. /log info ("Ending "$sname" script");
複製代碼
how to amend and make it work on a lists of keyword;
  1. :local lname "tiktok_ips";  # Address list name
  2. :local domains {"tiktokcdn", "tiktokv", "tiktok", "byteoversea", "musical-ly", "tiktokapi", "tik-tok", "ttwapi", "ixigua", "amemv", "snssdk", "pstatp", "byteimg", "zjbyte"};
  3. :local timeout "1d";  # Address list entry timeout

  4. /log info ("Starting TikTok DNS capture script");

  5. :foreach sname in=$domains do={
  6.     /log info ("Checking domain pattern "$sname"");
  7.    
  8.     # Search DNS cache for entries matching the domain pattern
  9.     :foreach i in=[/ip dns cache find where name~"$sname"] do={
  10.         :local resolvedIP [/ip dns cache get $i address];
  11.         
  12.         # Check if IP address was resolved and is not already in the address list
  13.         :if (($resolvedIP != "") && ([/ip firewall address-list find where address=$resolvedIP] = nil)) do={
  14.             :local cacheName [/ip dns cache get $i name];
  15.             /log info ("Adding TikTok IP: $resolvedIP for domain $cacheName to address list $lname");
  16.             
  17.             # Add the IP to the address list with a timeout
  18.             /ip firewall address-list add address=$resolvedIP list=$lname timeout=$timeout;
  19.         } else={
  20.             :log info ("No new IP for "$sname" or already in list");
  21.         }
  22.     }
  23. }

  24. :log info ("TikTok DNS capture script completed");
複製代碼

返回列表