Last active
September 16, 2022 10:51
-
-
Save zulonas/ded661e37c66aff5d9d9d0a87f4c36c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <iface>" | |
exit 1 | |
fi | |
mac=$(cat /sys/class/net/$1/address) | |
mac1=$(echo $mac | awk -F ':' '{print "0x"$1}') | |
mac2=$(echo $mac | awk -F ':' '{print "0x"$2}') | |
mac3=$(echo $mac | awk -F ':' '{print "0x"$3}') | |
mac4=$(echo $mac | awk -F ':' '{print "0x"$4}') | |
mac5=$(echo $mac | awk -F ':' '{print "0x"$5}') | |
mac6=$(echo $mac | awk -F ':' '{print "0x"$6}') | |
sum=0 | |
sum=$(($sum + ($mac1 * 1))) | |
sum=$(($sum + ($mac2 * 2))) | |
sum=$(($sum + ($mac3 * 3))) | |
sum=$(($sum + ($mac4 * 4))) | |
sum=$(($sum + ($mac5 * 5))) | |
sum=$(($sum + ($mac6 * 6))) | |
sum=$((($sum % 0xFE00) + 0x0100)) | |
IPV4LL_NETWORK=$((0xA9FE0000)) | |
ip=$(($IPV4LL_NETWORK | $sum)) | |
ip1=$(($ip >> 24)) | |
ip2=$((($ip & 0xff0000) >> 16)) | |
ip3=$((($ip & 0xff00) >> 8)) | |
ip4=$(($ip & 0xff)) | |
printf "%d.%d.%d.%d" $ip1 $ip2 $ip3 $ip4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment