Skip to content
Advertisement

Way to generate virtual mac address in PHP

I am working on web application where I will need to generate demo mac address for each record. There will be plenty of records for which I will need demo mac address.

So how to generate unique mac address using PHP?

Note – I don’t want exact mac address – I will need something unique like mac address but not UUID.

For Example – 00:17:88:00:00:00

Advertisement

Answer

echo implode(':', str_split(substr(md5(mt_rand()), 0, 12), 2));

https://eval.in/768041 or without hash

echo implode(':', str_split(str_pad(base_convert(mt_rand(0, 0xffffff), 10, 16) . base_convert(mt_rand(0, 0xffffff), 10, 16), 12, '0'), 2));

https://eval.in/768040

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement