Check mac match

I want to check if the server has a particular mac address, e.g.
if (get_mac_address() == “cc-da-06…”) {
is it good to compare just like it is? or better to convert to decimal before compare? e.g.
if (get_mac_address() == “170.46-…”) {
or better to hash it?
if (md5(get_mac_address()) == “agd6454gdyh…”) {
which way is better?

However you find the data, when you get it, is how you should compare it. In all situations you mention, the value is a string, so any additional conversion is just (unnecessary?) overhead. Or, there is something you are concerned about that I am not understanding.


A unique string is a unique string, regardless of it’s format. (If this were not true, ciphers would be impossible).

As Scott says, there is no value to converting the string - unless there is something else you’re trying to do with the string at some later point, obviously.

On *nix servers, mac is always - separated or always : separated or it depends and may have whatever separator? if yes, what are other separators?

Why does it matter how the mac address is separated? As an ID, you must store it first, to compare it later.


No, not for storing, I want to create a regexp validator, this is why I asked for separator.

I am not a regex guru, but it looks like you have what you need.


and what about separators? whate are possible separators on *nix?

I am not sure, but it looks like most of the time it is a colon.



For the record: the separator would be entirely dependent on how you’re actually retrieving the data.If you’re getting the data from a command prompt command, it may be one format, if it’s a script on a website it’s another. I could create an API that spits out a MAC seperated by !@!#(&* if i wanted to.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.