1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
# Append a default search path.
PATH="$PATH:/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
export PATH
# Exclude some devices, like lo, sit0, lxc*...
# This is regular expression format.
exluding_dev="(lo|sit[0-9]+|lxc.*)"
export LC_ALL=C
if [ -d /sys/class/net/ ]; then
# kernel support sysfs, so get the NIC devices from /sys
NETDEVICES="$(unalias ls &>/dev/null; ls /sys/class/net/ | grep -v -E "^$exluding_dev")"
elif [ -f /proc/net/dev ]; then
# kernel do not support sysfs, so get the NIC devices from /proc
NETDEVICES="$(cat /proc/net/dev | grep "^.*:" | cut -d: -f1 | grep -v -E "^$exluding_dev")"
else
exit 1
fi
echo "$NETDEVICES"
exit 0
|