Mikrotik Find Voip Devices and Add to Address List Script

add interval=5m name=VOIP_Phones_Sched on-event="/system script run VOIP_PHONES" policy=read,write start-date=jan/01/2016 start-time=18:31:44
/system script
add name=VOIP_PHONES owner=admin policy=read,write source=":global IsMACInteresting do={\r\
    \n\t :local InterestingPrefixes {\"00:15:65\";\"80:5E:C0\";\"64:16:7F\";\"00:04:F2\";\"00:0B:82\";\"00:04:13\"}\r\
    \n\t :local MyMACPrefix [:pick \$fullmac 0 8]\r\
    \n\t :local MACFlagged false\r\
    \n\t :foreach Prefix in=\$InterestingPrefixes do={\r\
    \n\t\t  :if (\$MyMACPrefix = \$Prefix) do={ :set \$MACFlagged true }\r\
    \n\t }\r\
    \n\t :return \$MACFlagged\r\
    \n}\r\
    \n\r\
    \n:foreach ListItem in=[ /ip firewall address-list find list=\"VOIP_Phones\"] do={\r\
    \n\r\
    \n/ip firewall address-list\r\
    \n:local MyIP [get \$ListItem address]\r\
    \n\r\
    \n:if ([:len [/ip arp find address=\$MyIP]] = 0) do={\r\
    \n\t\t  /ip firewall address-list remove [/ip firewall address-list find list=\"VOIP_Phones\" address=\$MyIP]\r\
    \n\t } else={\r\
    \n\t /ip arp\r\
    \n\t :if ([\$IsMACInteresting fullmac=[get [/ip arp find address=\$MyIP] mac-address]] = false) do={\r\
    \n\t\t\t   /ip firewall address-list remove [/ip firewall address-list find list=\"VOIP_Phones\" address=\$MyIP]\r\
    \n\t\t  }\r\
    \n\t }\r\
    \n}\r\
    \n\r\
    \n\r\
    \n/ip arp\r\
    \n:foreach ArpEntry in=[ /ip arp find ] do={\r\
    \n\t :local MyIP [get \$ArpEntry address]\r\
    \n\t :if ([:len [/ip firewall address-list find list=\"VOIP_Phones\" address=\$MyIP]] = 0) do={\r\
    \n\t\t  :if ([\$IsMACInteresting fullmac=[get \$ArpEntry mac-address]]) do={\r\
    \n\t\t\t   /ip firewall address-list add list=\"VOIP_Phones\" address=\$MyIP  \r\
    \n\t\t  }\r\
    \n\t }\r\
    \n}"





Or by itself

:global IsMACInteresting do={
     :local InterestingPrefixes {"00:15:65";"80:5E:C0";"64:16:7F";"00:04:F2";"00:0B:82";"00:04:13"}
     :local MyMACPrefix [:pick $fullmac 0 8]
     :local MACFlagged false
     :foreach Prefix in=$InterestingPrefixes do={
          :if ($MyMACPrefix = $Prefix) do={ :set $MACFlagged true }
     }
     :return $MACFlagged
}

:foreach ListItem in=[ /ip firewall address-list find list="VOIP_Phones"] do={

/ip firewall address-list
:local MyIP [get $ListItem address]

:if ([:len [/ip arp find address=$MyIP]] = 0) do={
          /ip firewall address-list remove [/ip firewall address-list find list="VOIP_Phones" address=$MyIP]
     } else={
     /ip arp
     :if ([$IsMACInteresting fullmac=[get [/ip arp find address=$MyIP] mac-address]] = false) do={
               /ip firewall address-list remove [/ip firewall address-list find list="VOIP_Phones" address=$MyIP]
          }
     }
}


/ip arp
:foreach ArpEntry in=[ /ip arp find ] do={
     :local MyIP [get $ArpEntry address]
     :if ([:len [/ip firewall address-list find list="VOIP_Phones" address=$MyIP]] = 0) do={
          :if ([$IsMACInteresting fullmac=[get $ArpEntry mac-address]]) do={
               /ip firewall address-list add list="VOIP_Phones" address=$MyIP  
          }
     }
}

  • MIKROTIK, ROUTER
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Mikrotik Dynamic DNS Update Script for No-IP DNS

This script was designed to utilize the No-IP Update API which offers direct access to No-IP's...

Manual:The Dude v6/The Dude server on hEX RB750Gr3

Overview New hEX (RB750Gr3) unit is ideal for small to medium size The Dude server...

Powered by WHMCompleteSolution