代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#ac=`ifconfig -a | grep encap | awk '{print $1}'`
ac=`
ifconfig
|
grep
encap |
awk
'{print $1}'
`
for
i
in
$ac
do
if
[ $i ==
"lo"
];
then
echo
$i
ifconfig
$i |
grep
"inet addr"
|
sed
's/ //g'
|
awk
'{print $2}END{print $3}'
else
echo
$i
ad=`
ethtool
$i |
sed
's/\t//g'
|
grep
'Speed\|Duplex'
`
ifconfig
$i |
grep
"inet addr"
|
sed
's/ //g'
|
awk
'{print $2}END{print $4}'
echo
$ad |
awk
'{print $1 $2}END{print $3 $4}'
fi
echo
-e
"\r"
done
gw=`
netstat
-rn |
grep
"^0.0.0.0"
|
awk
'{print $2}'
`
echo
"Default Gateway:"
$gw
|
运行结果如下:
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@localhost]
# sh t.sh
eth0
addr:10.12.1.134
Mask:255.255.255.224
Speed:1000Mb
/s
Duplex:Full
lo
addr:127.0.0.1
Mask:255.0.0.0
Default Gateway:10.12.1.129
|
本文转自flyingzf 51CTO博客,原文链接:http://blog.51cto.com/flyingzf/1767270,如需转载请自行联系原作者