Community discussions

MikroTik App
 
dima1002
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Fri Jan 26, 2018 8:40 pm

Find Mikrotik on the Switch

Fri Aug 25, 2023 3:06 pm

Hi,

I have a script here that displays the port on a switch on which a Mikrotik device is located.
But we have VLAN here, such as VLAN100, VLAN200, etc.

Can the script be optimized? Or what do you think about this?
:foreach i in=[/interface bridge host find] do={
  :local vid [/interface bridge host get $i vid]
  :local port [/interface bridge host get $i interface]
  :local mac [/interface bridge host get $i mac-address]
  :local vendor "unkown"
 
  :if (($vid != 1) && ($vid != 99) && ($vid < 100 || $vid > 2000) && !($port ~ "bridge" || $port ~ "sfp")) do={
 
    :if ($mac ~ "00:0C:42" || $mac ~ "08:55:31" || $mac ~ "18:FD:74" || $mac ~ "2C:C8:1B" || $mac ~ "48:8F:5A" || $mac ~ "48:A9:8A" || $mac ~ "4C:5E:0C" || $mac ~ "64:D1:54" || $mac ~ "6C:3B:6B" || $mac ~ "74:4D:28" || $mac ~ "78:9A:18" || $mac ~ "B8:69:F4" || $mac ~ "C4:AD:34" || $mac ~ "CC:2D:E0" || $mac ~ "D4:CA:6D" || $mac ~ "DC:2C:6E" || $mac ~ "E4:8D:8C") do={ 
      :set vendor "MikroTik" 
    }
 
    :if ($vendor = "MikroTik") do={
      :put ("MAC-Adresse: " . $mac . " is Vendor: " . $vendor . " und ist am Port: " . $port . " VID: " . $vid)
    }
  }
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Find Mikrotik on the Switch

Fri Aug 25, 2023 4:00 pm

where is the ^ ???
"00:0C:42" match also xx:00:0C:42:xx:xx, xx:xx:00:0C:42:xx and xx:xx:xx:00:0C:42

!($port ~ "bridge" || $port ~ "sfp") => !($port ~ "(bridge|sfp)")

... code

:if ($mac~"^(\
             00:0C:42|\
             08:55:31|\
             18:FD:74|\
             2C:C8:1B|\
             48:8F:5A|\
             48:A9:8A|\
             4C:5E:0C|\
             64:D1:54|\
             6C:3B:6B|\
             74:4D:28|\
             78:9A:18|\
             B8:69:F4|\
             C4:AD:34|\
             CC:2D:E0|\
             D4:CA:6D|\
             DC:2C:6E|\
             E4:8D:8C\
            )") do={:set vendor "MikroTik"}

Who is online

Users browsing this forum: No registered users and 11 guests