#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
export PATH
LANG=en_US
export LANG
MATCH=ether
if [ $(uname) = Darwin ]; then
nproc=`sysctl hw.physicalcpu|sed -e 's/^.*  *//'`
else
CPUINFOprocessor='processor'
#nproc=`cat /proc/cpuinfo|egrep -i "^${CPUINFOprocessor}"| wc -l`
nproc=`lscpu -p | egrep -v '^#' | sort -u -t, -k 2,4 | wc -l`
fi

ifconfig=
type ifconfig 1>/dev/null 2>&1 && ifconfig="ifconfig"
type ip       1>/dev/null 2>&1 && ifconfig="ip link"
if test "x${ifconfig}" = x ; then
 echo "no ifconfig or ip found"
 exit 1
fi

macs=
for n in `${ifconfig} 2>/dev/null | sed -e 's/HWaddr/ether/g' -e "/00:00:00:00:00:00:00:00:00:00:00:00/d" -e "/${MATCH}/{s/^.*${MATCH} */${nproc}m/;s/://g;s/ .*//g;y/ABCDEF/abcdef/;n;}" -e 'd' |sort|uniq` ; do macs=$macs:$n ; done
echo $macs | sed -e 's/^://'
