Community discussions

MikroTik App
 
DoubleDB
newbie
Topic Author
Posts: 25
Joined: Thu Feb 20, 2020 12:53 am

Check if string is contained in a file

Sun Aug 28, 2022 1:07 pm

Hello,

Is it possible to use scripting to check if a string is contained within a .csv file?
The idea is - I've downloaded an csv database containing mac vendor identifiers, for example:

Mac Prefix,Vendor Name,Private,Block Type,Last Update
E0:2B:96,"Apple, Inc.",false,MA-L,2020/04/09
. . .

What I want to do is when an user connects to hotspot - I can strip the mac address, leaving only the first 3 pairs and check against the CSV file (using script placed in hotspot profile "On Login" - and only if the mac-address is empty (i.e. the card isn't used already) - to reduce any unnecessary checks and CPU resource waste)

If there's no match - simply disallow the user from authenticating (for example - force disconnect).
And all this because there are some cards that only permit a single device (by MAC locking), and a lot of tourists don't turn off the "Private MAC/Wi-Fi address" option when getting such a card, then after a day or two start crying on reception: "it doesn't work". So this would "force" them to turn off the setting on the first login.

The database can be found here: https://maclookup.app/downloads/csv-database
Supposedly it's frequently updated, so re-downloading it once every few days won't be an issue.

Any ideas on how to do the actual checking of the mac string against the CSV?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Check if string is contained in a file

Sun Aug 28, 2022 10:31 pm

Do not use CSV, just check if the Locally administered bit on MAC is set...
Simpler than this...
:if ("00:0C:48:AA:BB:CC"~"^[0-9A-Fa-f][048Cc]") do={ :put "Universal Unicast" } else={ :put "Not Universal Unicast" }

Obviously you do not have any warranty than one advanced user can use random valid MAC.
 
DoubleDB
newbie
Topic Author
Posts: 25
Joined: Thu Feb 20, 2020 12:53 am

Re: Check if string is contained in a file

Sat Sep 03, 2022 10:30 am

Do not use CSV, just check if the Locally administered bit on MAC is set...
Simpler than this...
:if ("00:0C:48:AA:BB:CC"~"^[0-9A-Fa-f][048Cc]") do={ :put "Universal Unicast" } else={ :put "Not Universal Unicast" }

Obviously you do not have any warranty than one advanced user can use random valid MAC.

This isn't exactly useful because various vendors use different "randomized" ranges. The CSV (should) contain only the "valid" ranges used by devices.
I've just checked several MACs in the hotel - 90% of the randomized addresses don't match with 048Cc, but 100% of the "real" MACs match with the CSV.
Obviously the randomized ranges shouldn't match with an already occupied range, so, matching against the CSV is still the better option because the randomized ranges don't exist in there.

Example:
:if ("C2:7D:7D:44:68:03"~"^[0-9A-Fa-f][048Cc]") do={ :put "Universal Unicast" } else={ :put "Not Universal Unicast" }
Not Universal Unicast

Another example of my iPhone with "Private Wi-Fi Address" enabled:
:if ("26:BD:01:C8:AE:DF"~"^[0-9A-Fa-f][048Cc]") do={ :put "Universal Unicast" } else={ :put "Not Universal Unicast" }
Not Universal Unicast

However, when I disable that option - the MAC matches with an entry in the CSV.

So.. back to the original question - what's the best way to load the CSV into memory (it's 2.6 kB) and check against it's entries.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Check if string is contained in a file

Sat Sep 03, 2022 2:55 pm

Which manufacturer is C2:7D:7D inside your csv?

Probably you do not understand what Locally administered bit on MAC is.
The random MAC generated must never have Locally administered bit set to 0.
 
DoubleDB
newbie
Topic Author
Posts: 25
Joined: Thu Feb 20, 2020 12:53 am

Re: Check if string is contained in a file

Sat Sep 03, 2022 8:43 pm

Which manufacturer is C2:7D:7D inside your csv?

Probably you do not understand what Locally administered bit on MAC is.
The random MAC generated must never have Locally administered bit set to 0.
Tested with all MAC addresses, got it.

Who is online

Users browsing this forum: No registered users and 22 guests