Is there any possibility that I can get MAC Addresses of Mobile devices like ANDROID / IPHONE from the Mikrotik DHCP Leases ?
I want to get there HOSTNAME name and MAC Address (or mac addresses in ADDRESS LIST or file or whatever possible )
[/ip dhcp-server lease print detail as-value]
[/ip dhcp-server lease print detail as-value where host-name~"android\\-"]
:foreach dev in=[/ip dhcp-server lease print detail as-value where host-name~"android\\-"] do={
/log info ("Device with MAC address" . ($dev->"active-mac-address") . " has the hostname " . ($dev->"host-name"));
};
Thank you it worked !To write all android devices' MACs and hostnames to the router log:Code: Select all:foreach dev in=[/ip dhcp-server lease print detail as-value where host-name~"android\\-"] do={ /log info ("Device with MAC address" . ($dev->"active-mac-address") . " has the hostname " . ($dev->"host-name")); };
/ip firewall address-list add address=($dev->"active-address") list=mobile-devices
HI Oxygeno20,
Can you help me out on this script? It is not running on v6.42.7
:local SERVER “server250”;
:local INTERFACEFILTER “combo1-core-switch”;
# # AUTOR: NICOLAS DAITSCH
# # www.tech-nico.com
# # Modified by Oseni Abiola
:foreach i in=[/ip dhcp-server lease find dynamic=yes active-server=$SERVER] do={
:local DhcpDynIP [/ip dhcp-server lease get $i active-address];
:local DhcpDynMAC [/ip dhcp-server lease get $i mac-address];
:local DhcpDynHOST [/ip dhcp-server lease get $i host-name];
:local IfMacExist [/ip firewall filter find src-mac-address="$DhcpDynMAC"];
:local phoneNAME [:pick $DhcpDynHOST 0 6];
:if ( ($phoneNAME=“Redmi”) || ($phoneNAME=“IPHONE”) || ($phoneNAME=“HUAWEI”) || ($phoneNAME=“iPhone”) || ($phoneNAME=“Galaxy”) || ($phoneNAME="androi") || ($phoneNAME="Window") || ($phoneNAME="Androi") || ($phoneNAME="BLACKB") || ([:len $DhcpDynHOST]=0) ) do={
:if ($IfMacExist != "") do={
# :log error (“filtering Phone… ".$DhcpDynMAC. " It already exists“)
} else= {
/ip firewall filter add action=add-src-to-address-list address-list=mobile chain=forward in-interface=$INTERFACEFILTER src-address="$DhcpDynMAC" comment=$DhcpDynHOST;
:log warning (“Mobile Phone Captured" . $phoneNAME . " MAC: " . $DhcpDynMAC);
}
}
}
Thank you for your reply.
Regards
:do {/ip firewall raw
add action=drop chain=prerouting src-address-list="BlockLeaseIPs"
}
:do {
:local HostList {"androi"; "Androi"; "Galaxy"; "BLACKB"; "IPHONE"; "iPhone"; "HUAWEI"};
:if ($leaseBound=0) do={/ip firewall address-list remove number=[find where address=$leaseActIP && list="BlockLeaseIPs"]}
:if ($leaseBound=1) do={
:local HostName [:pick [/ip dhcp-server lease get number=[find where address=$leaseActIP] host-name] 0 6];
:if ( [:len $HostName]=0 ) do={
:do {/ip firewall address-list add address=$leaseActIP list="BlockLeaseIPs"
} on-error={:log error message=("add address=$leaseActIP list=BlockLeaseIPs exist.")}
}
:foreach ix in=[ $HostList ] do={
:if ( $HostName=$ix ) do={
:do {/ip firewall address-list add address=$leaseActIP list="BlockLeaseIPs"
} on-error={:log error message=("add address=$leaseActIP list=BlockLeaseIPs exist.")}
}
}
}} on-error={:log error message="lease-script failed..."}