Scripting Ideas ??

Weird way of doing it, but ok.

Try this:

{
    :local ddosedList [/ip firewall address-list find list=ddosed]
    :foreach ddosedEntry in=$ddosedList do={
        :local ddosedIp [/ip firewall address-list get $ddosedEntry address]
        :if ([:len [/ip route find comment=ddosed dst-address="$ddosedIp/32"]] = 0) do={
            /ip route add bgp-communities=1111:333 comment=ddosed distance=1 dst-address="$ddosedIp/32" type=blackhole
        }
    }
}
{
    :local blackholeList [/ip route find comment=ddosed]
    :foreach blackholeEntry in=$blackholeList do={
        :local blackholeIp [/ip route get $blackholeEntry dst-address]
        :set blackholeIp [:pick $blackholeIp 0 [:find $blackholeIp "/" -1]]
        :if ([:len [/ip firewall address-list find list=ddosed address=$blackholeIp]] = 0) do={
            /ip route remove $blackholeEntry
        }
    }
}

It worked in my little test at least.
I couldn’t think of a better way to do it than check each list one at a time.

Thank you very much… thanks a lot… thats wonderfull.. thats what i want :slight_smile:

Thanks Thanks Thanks

Hi Sinan,
i need help with this script:

:local phone “android”;
:local telefon value=[/ip dhcp-server lease find dynamic=yes host-name~$phone];
:foreach looping in=$telefon do={
:local mac value=[/ip dhcp-server lease get $looping value-name=active-mac-address];
/ip firewall filter add chain=forward src-mac-address=$mac action=reject comment=szkriptdroid disabled=no
/ip dhcp-server lease remove [/ip dhcp-server lease find dynamic=yes active-mac-address=$mac];
log info $mac;
};

it works as i want but it fills the firewall with same mac addresses, so i need to filter out already added addresses. i tried if statement but im bad in programing and didnt succeded. please help

.

:local phone "android"
:local phoneLeases [/ip dhcp-server lease find dynamic=yes host-name~$phone]
:foreach looping in=$phoneLeases do={
    :local mac [/ip dhcp-server lease get $looping active-mac-address]
    :if ([:len [/ip firewall filter find src-mac-address=$mac]] = 0) do={
        /ip firewall filter add chain=forward src-mac-address=$mac action=reject comment="szkriptdroid" disabled=no
        /ip dhcp-server lease remove $looping
        :log info "Mac address \"$mac\" blocked for having \"$phone\" in the name."
    }
}

I didn’t test it, but I think this should work better.

Thank you very much. It works as I wanted

please help me! http://forum.mikrotik.com/t/need-help-about-a-script/104659/1