File: get-nic-devs

package info (click to toggle)
drbl 5.7.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,984 kB
  • sloc: sh: 43,503; perl: 8,820; xml: 867; makefile: 131
file content (23 lines) | stat: -rwxr-xr-x 738 bytes parent folder | download | duplicates (2)
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