標題:
help - Mikrotik Script for capture tiktok ip
[打印本頁]
作者:
carlchan
時間:
2024-11-1 14:52
標題:
help - Mikrotik Script for capture tiktok ip
This script work on only one keyword;
:local sname "tiktok" ;
:local lname "us-only" ;
#/log info ("Starting "$sname" script");
:foreach i in=[/ip dns cache all find where (name~"$sname")] do={
:local tmpAddress [/ip dns cache get $i name];
:if ( [/ip firewall address-list find where address=$tmpAddress] = "") do={
:local cacheName [/ip dns cache get $i name] ;
#/log info ("added entry: $cacheName $tmpAddress");
/ip firewall address-list add address=$tmpAddress list=$lname timeout=00:01:00 ;
}
}
/log info ("Ending "$sname" script");
複製代碼
how to amend and make it work on a lists of keyword;
:local lname "tiktok_ips"; # Address list name
:local domains {"tiktokcdn", "tiktokv", "tiktok", "byteoversea", "musical-ly", "tiktokapi", "tik-tok", "ttwapi", "ixigua", "amemv", "snssdk", "pstatp", "byteimg", "zjbyte"};
:local timeout "1d"; # Address list entry timeout
/log info ("Starting TikTok DNS capture script");
:foreach sname in=$domains do={
/log info ("Checking domain pattern "$sname"");
# Search DNS cache for entries matching the domain pattern
:foreach i in=[/ip dns cache find where name~"$sname"] do={
:local resolvedIP [/ip dns cache get $i address];
# Check if IP address was resolved and is not already in the address list
:if (($resolvedIP != "") && ([/ip firewall address-list find where address=$resolvedIP] = nil)) do={
:local cacheName [/ip dns cache get $i name];
/log info ("Adding TikTok IP: $resolvedIP for domain $cacheName to address list $lname");
# Add the IP to the address list with a timeout
/ip firewall address-list add address=$resolvedIP list=$lname timeout=$timeout;
} else={
:log info ("No new IP for "$sname" or already in list");
}
}
}
:log info ("TikTok DNS capture script completed");
複製代碼
歡迎光臨 電訊茶室 (http://www.telecom-cafe.com/forum/)
Powered by Discuz! 7.2