Re: add mac address

#54546

sergicurtu
Member

You can add this script to script/cron .

You have to create a new file (file_mac.db) with one line for every mac . In every line you have to put 3 parameters (; separated) :

1) text description
2) MAC address
3) static ip

Note : I’m adding MAC into subnet 05 !!!!

#!/bin/sh

. /etc/kerbynet.conf

_input=/root/file_mac.db

[ ! -f “$_input” ] && { echo “$0: File $_input not found.”; exit 1; }

# Filtrar comentaris i línies en blanc
# afegir cada línia a la variable $linia_actual

egrep -v “^#|^$” x | while IFS= read -r linia_actual
do

# linia_actual=”2013/2014 : aarroXXX@iesnuXXX.cat;0C:84:A0:6B:4D:81;192.168.172.1″

# every line : “info_text;MAC;fixed IP”

# estructura : descripcó MAC ip separats per ;

SUBNET=”05″
MAC=””
IP=””
DESC=””
PARAMETERS=””

IFS=’;’ read -ra ADDR < << "$linia_actual" declare j number
j=1

for i in “${ADDR[@]}”; do

if [ “$j” -eq 1 ]; then DESC=$i
echo “DESCRIPCIÓ : $DESC ” ;
fi

if [ “$j” -eq 2 ]; then MAC=$i
echo “MAC : $MAC ” ;
fi

if [ “$j” -eq 3 ]; then IP=$i
echo “IP : $IP ” ;
fi

j=$((j+1))

done

[ -z “$SUBNET” -o -z “$IP” -o -z “$MAC” ] && exit 1
CONFIG=”$REGISTER/system/dhcp”
if ! [ -d $CONFIG/subnets/$SUBNET ] ; then
echo “Subnet does not exist.” 1>&2
exit 3
fi
MAC=`echo $MAC |awk -F”:” ‘{printf “%02s:%02s:%02s:%02s:%02s:%02s”,$1,$2,$3,$4,$5,$6}’`
if ! [ -d $CONFIG/subnets/$SUBNET/Statics ] ; then
mkdir $CONFIG/subnets/$SUBNET/Statics
fi
cd $CONFIG/subnets/$SUBNET/Statics

NUMIP=`echo $IP | awk -F”.” ‘{printf “%010d”,($1*256*256*256+$2*256*256+$3*256+$4)}’`

NUMMAC=`echo $MAC |sed “s/://g”`
ENTRY=”${NUMIP}_${NUMMAC}”
if [ -d “$ENTRY” ] ; then
echo “Entry already exists.” 1>&2
exit 4
fi
mkdir “$ENTRY”
echo $IP > $ENTRY/IP
echo $MAC > $ENTRY/MAC
echo “$DESC” > $ENTRY/Desc
echo “$PARAMETERS” > $ENTRY/Parameters
$SCRIPTS/dhcp_start
done < "${_input}" Sergi