1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
# Description: Get the IP address of network card interface
ethx=$1
export LC_ALL=C
Usage() {
echo "Get the IP address of network card interface"
echo "Usage:"
echo "$(basename $0) INTERFACE"
echo "Ex: $(basename $0) eth0"
}
[ -z "$ethx" ] && Usage && exit 1
if ! LC_ALL=C ifconfig -a 2>/dev/null | grep -i -q "\<$ethx\>"; then
exit 1
fi
LC_ALL=C ifconfig $ethx | grep -A1 $ethx | grep -v $ethx | grep "inet addr" | sed -e 's/^.*inet addr:\([0-9\.]\+\).*$/\1/'
exit 0
|