Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 44 additions & 14 deletions wipri
Original file line number Diff line number Diff line change
Expand Up @@ -215,28 +215,58 @@ function hostn {
dhclient $netdev || echo -e "${RED}dhclient not found - OK we can still make due without it${ENDCOLOR}"
}

#######################################################
# Function to check if a MAC address's last three octets match any existing interface NICs except for the loopback interface.
# This is for essentially blacklisting any real NIC's in random mac generation.
check_mac_conflict() {
local new_mac=$1
local new_last_three_octets=$(echo "$new_mac" | awk -F: '{print $(NF-2)":"$(NF-1)":"$NF}')

for iface in /sys/class/net/*; do
if [ -f "$iface/address" ] && [ "$(basename "$iface")" != "lo" ]; then
existing_mac=$(cat "$iface/address")
existing_last_three_octets=$(echo "$existing_mac" | awk -F: '{print $(NF-2)":"$(NF-1)":"$NF}')
if [ "$new_last_three_octets" == "$existing_last_three_octets" ]; then
return 0 # Conflict found
fi
fi
done

return 1 # No conflict
}

#######################################################
# MAC randomization/setting
function macrand {
hexchar="abcdef0123456789"
beg=$(shuf -n 1 $oui_file) # $oui_file contains important info to generate valid random macs: ma>
end=$( for i in {1..6} ; do echo -n ${hexchar:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' )
mac=$beg$end
/bin/echo -e "${BLUE}Changing MAC to:${ENDCOLOR} $RED$mac$ENDCOLOR"
ip link set dev $netdev down;ip link set dev $netdev address $mac;ip link set dev $netdev up;
echo ""
hexchar="abcdef0123456789"
while true; do
beg=$(shuf -n 1 $oui_file) # $oui_file contains important info to generate valid random macs
end=$( for i in {1..6} ; do echo -n ${hexchar:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' )
mac=$beg$end
if ! check_mac_conflict "$mac"; then
break
fi
done
/bin/echo -e "${BLUE}Changing MAC to:${ENDCOLOR} $RED$mac$ENDCOLOR"
ip link set dev $netdev down;ip link set dev $netdev address $mac;ip link set dev $netdev up;
echo ""
}

#######################################################
# MAC randomization (phone version- temp version)
function phmacrand {
hexchar="abcdef0123456789"
beg=$(shuf -n 1 $phoui_file) # $phoui_file contains important info to generate valid random phone macs
end=$( for i in {1..6} ; do echo -n ${hexchar:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' )
mac=$beg$end
/bin/echo -e "${BLUE}Changing MAC to:${ENDCOLOR} ${RED}$mac${ENDCOLOR}"
ip link set dev $netdev down;ip link set dev $netdev address $mac;ip link set dev $netdev up;
echo ""
hexchar="abcdef0123456789"
while true; do
beg=$(shuf -n 1 $phoui_file) # $phoui_file contains important info to generate valid random phone macs
end=$( for i in {1..6} ; do echo -n ${hexchar:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' )
mac=$beg$end
if ! check_mac_conflict "$mac"; then
break
fi
done
/bin/echo -e "${BLUE}Changing MAC to:${ENDCOLOR} ${RED}$mac${ENDCOLOR}"
ip link set dev $netdev down;ip link set dev $netdev address $mac;ip link set dev $netdev up;
echo ""
}

########################################################
Expand Down