-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathnddchecker.ksh
93 lines (91 loc) · 3.38 KB
/
nddchecker.ksh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
##
#!/bin/sh
# Print column header information
/usr/bin/echo "Interface\tSpeed\t\tDuplex"
/usr/bin/echo "---------\t-----\t\t------"
# Determine the speed and duplex for each live NIC on the system
for INTERFACE in `/usr/bin/netstat -i | /usr/bin/egrep -v "^Name|^lo0" \
| /usr/bin/awk '{print $1}' | /usr/bin/cut -d: -f1 |/usr/bin/sort \
| /usr/bin/uniq`
do
# "ce" interfaces
if [ "`/usr/bin/echo $INTERFACE \
| /usr/bin/awk '/^ce[0-9]+/ { print }'`" ] ; then
# Determine the ce interface number
INSTANCE=`/usr/bin/echo $INTERFACE | cut -c 3-`
DUPLEX=`/usr/bin/kstat ce:$INSTANCE | /usr/bin/grep link_duplex \
| /usr/bin/awk '{ print $2 }'`
case "$DUPLEX" in
1) DUPLEX="half" ;;
2) DUPLEX="full" ;;
esac
SPEED=`/usr/bin/kstat ce:$INSTANCE | /usr/bin/grep link_speed \
| /usr/bin/awk '{ print $2 }'`
case "$SPEED" in
10) SPEED="10 Mbit/s" ;;
100) SPEED="100 Mbit/s" ;;
1000) SPEED="1 Gbit/s" ;;
esac
# "bge" interfaces
elif [ "`/usr/bin/echo $INTERFACE \
| /usr/bin/awk '/^bge[0-9]+/ { print }'`" ] ; then
# Determine the bge interface number
INSTANCE=`/usr/bin/echo $INTERFACE | cut -c 4-`
DUPLEX=`/usr/bin/kstat bge:$INSTANCE:parameters \
| /usr/bin/grep link_duplex | /usr/bin/awk '{ print $2 }'`
case "$DUPLEX" in
1) DUPLEX="half" ;;
2) DUPLEX="full" ;;
esac
SPEED=`/usr/bin/kstat bge:$INSTANCE:parameters \
| /usr/bin/grep link_speed | /usr/bin/awk '{ print $2 }'`
case "$SPEED" in
10) SPEED="10 Mbit/s" ;;
100) SPEED="100 Mbit/s" ;;
1000) SPEED="1 Gbit/s" ;;
esac
# "iprb" interfaces
elif [ "`/usr/bin/echo $INTERFACE \
| /usr/bin/awk '/^iprb[0-9]+/ { print }'`" ] ; then
# Determine the iprb interface number
INSTANCE=`/usr/bin/echo $INTERFACE | cut -c 5-`
DUPLEX=`/usr/bin/kstat iprb:$INSTANCE \
| /usr/bin/grep duplex | /usr/bin/awk '{ print $2 }'`
SPEED=`/usr/bin/kstat iprb:$INSTANCE | /usr/bin/grep ifspeed \
| /usr/bin/awk '{ print $2 }'`
case "$SPEED" in
10000000) SPEED="10 Mbit/s" ;;
100000000) SPEED="100 Mbit/s" ;;
1000000000) SPEED="1 Gbit/s" ;;
esac
# le interfaces are always 10 Mbit half-duplex
elif [ "`/usr/bin/echo $INTERFACE \
| /usr/bin/awk '/^le[0-9]+/ { print }'`" ] ; then
DUPLEX="half"
SPEED="10 Mbit/s"
# All other interfaces
else
INTERFACE_TYPE=`/usr/bin/echo $INTERFACE | /usr/bin/sed -e "s/[0-9]*$//"`
INSTANCE=`/usr/bin/echo $INTERFACE | /usr/bin/sed -e "s/^[a-z]*//"`
# Only the root user can run /usr/sbin/ndd commands
if [ "`/usr/bin/id | /usr/bin/cut -c1-5`" != "uid=0" ] ; then
echo "You must be the root user to determine \
${INTERFACE_TYPE}${INSTANCE} speed and duplex information."
continue
fi
/usr/sbin/ndd -set /dev/$INTERFACE_TYPE instance $INSTANCE
SPEED=`/usr/sbin/ndd -get /dev/$INTERFACE_TYPE link_speed`
case "$SPEED" in
0) SPEED="10 Mbit/s" ;;
1) SPEED="100 Mbit/s" ;;
1000) SPEED="1 Gbit/s" ;;
esac
DUPLEX=`/usr/sbin/ndd -get /dev/$INTERFACE_TYPE link_mode`
case "$DUPLEX" in
0) DUPLEX="half" ;;
1) DUPLEX="full" ;;
*) DUPLEX="" ;;
esac
fi
/usr/bin/echo "$INTERFACE\t\t$SPEED\t$DUPLEX"
done