Community discussions

MikroTik App
 
Basic
just joined
Topic Author
Posts: 2
Joined: Fri Jan 20, 2023 5:10 pm

MikroTik how a network scanner.

Fri Jan 20, 2023 6:31 pm

Hi everyone! One week ago i'm found a script, which scanning only local network, but I'm need to scan all WAN port or ether1 and send all saved data, how a .txt document or a just message to e-mail.
# 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);
        }
    }
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: MikroTik how a network scanner.

Sat Jan 21, 2023 2:18 am

Where did you find the script?
Not even is for what you wrote,
it doesn't do any "scan", it just reads the bridge hosts table, ip addresses assigned to interfaces and dhcp leases.
It is not a scanner tools for things on the LAN (or WAN), it only shows what is known.
 
Basic
just joined
Topic Author
Posts: 2
Joined: Fri Jan 20, 2023 5:10 pm

Re: MikroTik how a network scanner.

Sun Jan 22, 2023 12:44 pm

Who is online

Users browsing this forum: Bing [Bot] and 17 guests