› Forums › Network Management › ZeroShell › Add a large amount of mac address from a file
- This topic is empty.
-
AuthorPosts
-
September 10, 2017 at 4:02 pm #44868
scoude
MemberHi,
how can I adding a large amount of mac address from a file for dhcp module ?
I don’t want to record them one by one !
Thank’s in advance !
October 23, 2017 at 9:45 am #54546sergicurtu
MemberYou 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 ipNote : 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_actualegrep -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=1for i in “${ADDR[@]}”; do
if [ “$j” -eq 1 ]; then DESC=$i
echo “DESCRIPCIÓ : $DESC ” ;
fiif [ “$j” -eq 2 ]; then MAC=$i
echo “MAC : $MAC ” ;
fiif [ “$j” -eq 3 ]; then IP=$i
echo “IP : $IP ” ;
fij=$((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/StaticsNUMIP=`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 -
AuthorPosts
- You must be logged in to reply to this topic.