www.zeroshell.org Forum Index www.zeroshell.org
Linux Distribution for server and embedded devices
 
 SearchSearch  RegisterRegister  UsergroupsUsergroups 
 ProfileProfile  Log inLog in  Log in to check your private messagesPrivate Message 

Add a large amount of mac address from a file

 
Post new topic   Reply to topic    www.zeroshell.org Forum Index -> ZeroShell
View previous topic :: View next topic  
Author Message
scoude



Joined: 19 Dec 2016
Posts: 2

PostPosted: Sun Sep 10, 2017 4:02 pm    Post subject: Add a large amount of mac address from a file Reply with quote

Hi,

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 !
Back to top
View user's profile Send private message
sergicurtu



Joined: 23 Oct 2017
Posts: 1

PostPosted: Mon Oct 23, 2017 9:45 am    Post subject: add mac address Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    www.zeroshell.org Forum Index -> ZeroShell All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group