Code: Select all
# Enumeration of interfaces
foreach interfaceIndex in=([ /interface find; ]) do={
:local interfaceName ([ /interface get $interfaceIndex name; ]);
:local bridgeIndexes ([ /interface bridge find; ]);
:local bridgeIP ("not IP-address");;
:local bridgeName ("not bridge name");
:local bridgeHosts;
# Enumeration of bridges
foreach bridgeIndex in=$bridgeIndexes do={
:set bridgeName ([ /interface bridge get $bridgeIndex name; ]);
:set bridgeHosts ([ /interface bridge host find bridge=$bridgeName; ]);
# Find IP address of bridges
foreach ipAddressIndex in=([ /ip address find; ]) do={
:local interfaceNameIpAddress ([ /ip address get $ipAddressIndex interface; ]);
:local interfaceHostIpAddress ([ /ip address get $ipAddressIndex address; ]);
if ($interfaceNameIpAddress = $bridgeName) do={ :set bridgeIP ($interfaceHostIpAddress); }
}
# Enumeration of hosts
foreach bridgeHost in=$bridgeHosts do={
:local hostMAC ([ /interface bridge host get $bridgeHost mac-address; ]);
:local hostInterface ([ /interface bridge host get $bridgeHost on-interface; ]);
:local hostComment ("no comments");
:local hostName ("not host name");
:local hostIP ("not IP-address");
if ([ /interface bridge host get $bridgeHost local; ] = true) do={
:set hostName ([ /system resource get board-name; ]);
:set hostIP ($bridgeIP);
}
# Checking for MAC-address in DHCP leases
if ([ /ip dhcp-server lease find mac-address=$hostMAC; ] != "") do={
:local hostNumber ([ /ip dhcp-server lease find mac-address=$hostMAC; ])
:set hostName ([ /ip dhcp-server lease get $hostNumber host-name; ]);
:set hostComment ([ /ip dhcp-server lease get $hostNumber comment; ]);
:set hostIP ([ /ip dhcp-server lease get $hostNumber address; ]);
}
# Output if interface and host names match
if (($interfaceName = $hostInterface) && ($interfaceName != $bridgeName)) do={
:put ($hostInterface." -> \t".$hostName." (".$hostMAC.")\t remark: ".$hostComment." -> \t".$hostIP." -> \t".$bridgeName);
}
}
}
# Enumeration ip addresses
foreach ipAddressIndex in=([ /ip address find; ]) do={
:local interfaceNameIpAddress ([ /ip address get $ipAddressIndex interface; ]);
:local interfaceHostIpAddress ([ /ip address get $ipAddressIndex address; ]);
:local interfaceMACAddress ([ :tostr [ /interface get [ /interface find name=$interfaceNameIpAddress ; ] mac-address ]]);
if ($interfaceMACAddress = "") do={ :set interfaceMACAddress ("not MAC-address"); }
:local hostName ([ /system resource get board-name; ]);
if ($interfaceName = $interfaceNameIpAddress) do={
:put ($interfaceNameIpAddress." -> \t".$hostName." (".$interfaceMACAddress.") -> \t".$interfaceHostIpAddress);
}
}
}