#########################################################################
## Name : get-ip-address.sh
## Author : Saurabh Gupta
## Date : PM 08:52 11 October 2011
## Desc : get the IP address
## Source : http://saurabhgupta0527.blogspot.com/p/shell-scipt.html
## Note :
#########################################################################
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "XXXXXXX Getting the Network Interface Card Information XXXXXXX"
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
IPLIST=`/sbin/ifconfig | grep "Bcast" | sed -e "s/.*addr:\([^ ]*\).*/\1/"`
## Name : get-ip-address.sh
## Author : Saurabh Gupta
## Date : PM 08:52 11 October 2011
## Desc : get the IP address
## Source : http://saurabhgupta0527.blogspot.com/p/shell-scipt.html
## Note :
#########################################################################
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "XXXXXXX Getting the Network Interface Card Information XXXXXXX"
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
IPLIST=`/sbin/ifconfig | grep "Bcast" | sed -e "s/.*addr:\([^ ]*\).*/\1/"`
echo "These are the current interfaces found on this system:"
cnt=0
for ii in $IPLIST; do
let cnt=$cnt+1
iface=`/sbin/ifconfig | awk '$0 ~ str{print b}{b=$1}' str="$ii"`
echo "[$cnt] $iface ($ii)"
LISTIP=( "${LISTIP[@]}" $ii )
LISTIF=( "${LISTIF[@]}" $iface )
done
echo ""
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#XXXXXXX Getting the Network Interface Card Information #XXXXXXX
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#
#These are the current interfaces found on this system:
#[1] eth0 (192.168.22.64)
#[2] virbr0 (192.168.122.1)
#
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#
cnt=0
for ii in $IPLIST; do
let cnt=$cnt+1
iface=`/sbin/ifconfig | awk '$0 ~ str{print b}{b=$1}' str="$ii"`
echo "[$cnt] $iface ($ii)"
LISTIP=( "${LISTIP[@]}" $ii )
LISTIF=( "${LISTIF[@]}" $iface )
done
echo ""
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
#
# OUTPUT
#
#[sgupta@rhel6x64 scripts]$ . ./get-ip-address.sh#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#XXXXXXX Getting the Network Interface Card Information #XXXXXXX
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#
#These are the current interfaces found on this system:
#[1] eth0 (192.168.22.64)
#[2] virbr0 (192.168.122.1)
#
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#
it worked correctly.
ReplyDeletethank you.
thnaks. let me know if you need any other scripts.
ReplyDelete--Saurabh Gupta
saurabh.gupta@ccplusplus.com