summaryrefslogtreecommitdiff
path: root/bin/NS2SetMac.sh
Side-by-side diff
Diffstat (limited to 'bin/NS2SetMac.sh') (more/less context) (ignore whitespace changes)
-rwxr-xr-xbin/NS2SetMac.sh22
1 files changed, 22 insertions, 0 deletions
diff --git a/bin/NS2SetMac.sh b/bin/NS2SetMac.sh
new file mode 100755
index 0000000..51810ae
--- a/dev/null
+++ b/bin/NS2SetMac.sh
@@ -0,0 +1,22 @@
+# store/set MAC address for given interface
+NS2MacStore=/etc/NS2
+
+[ ! -d ${NS2MacStore} ] && mkdir ${NS2MacStore}
+
+if [ -z "$1" ]
+then
+ exit 0
+fi
+
+if [ -f ${NS2MacStore}/$1.mac ]
+then
+ # set this mac
+ /sbin/ifconfig $1 hw ether `cat ${NS2MacStore}/$1.mac`
+else
+ # remember current mac for all times
+ X=`/sbin/ifconfig $1 | grep HWaddr`
+ X=${X#*HWaddr } # strip till HWaddr
+ X=${X%% *} # remove trailing spaces
+ echo ${X} > ${NS2MacStore}/$1.mac
+fi
+exit 0