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