get_new_macaddr: add 1 to the mac address instead of starting from 0x14
If someone have 2 adapters with the same hardware, there is a possibility the first 5 bytes of their mac address to be the same. I this case we will have mac address collision if we change both of them to XX:XX:XX:XX:XX:14, one way to avoid this is to add 1 to their last byte. Fix #47
This commit is contained in:
parent
ddd6bfad45
commit
5b2d7984db
@ -209,8 +209,9 @@ get_virt_iface_name() {
|
|||||||
|
|
||||||
get_new_macaddr() {
|
get_new_macaddr() {
|
||||||
OLDMAC=$(get_macaddr "$1")
|
OLDMAC=$(get_macaddr "$1")
|
||||||
for i in {20..255}; do
|
LAST_BYTE=$(printf %d 0x${OLDMAC##*:})
|
||||||
NEWMAC="${OLDMAC%:*}:$(printf %02x $i)"
|
for i in {1..255}; do
|
||||||
|
NEWMAC="${OLDMAC%:*}:$(printf %02x $(( ($LAST_BYTE + $i) % 256 )))"
|
||||||
(ip link | grep "ether ${NEWMAC}" > /dev/null 2>&1) || break
|
(ip link | grep "ether ${NEWMAC}" > /dev/null 2>&1) || break
|
||||||
done
|
done
|
||||||
echo $NEWMAC
|
echo $NEWMAC
|
||||||
|
Loading…
x
Reference in New Issue
Block a user